DEV Community

Strahinja
Strahinja

Posted on

One thing i really like about GO

I already enjoy so much working with GO and lately i was working improving API on Leprechaun switching from unix sockets to HTTP and i implemented something very simple which came to my mind when i was figuring out what to improve, what to change, what can be done better. Then this idea came to my mind, adding methods to primitive types which looks like this:

type Cmd string

func (c Cmd) agent() string {
    s := strings.Fields(string(c))
    return s[0]
}

func (c Cmd) command() string {
    s := strings.Fields(string(c))
    return s[1]
}    

func (c Cmd) args() []string {
    s := strings.Fields(string(c))
    return s[2:]
}

I would like to hear more about this from you people, ideas, implementations, etc...

Top comments (0)