Golang primer

My team and I are now using Golang in our projects. I knew my trusty Komodo IDE could handle Golang so I wasn’t worried.

However, I don’t know how to configure Golang and to my chagrin, I can’t seem to figure out how to do it. I would really appreciate some help. This is on a Linux system, btw.

In the Golang Language Configuration there are three items:

  1. “Use this Go tool”
  2. “Gocode Location”
  3. “Godef Location”

I’m guessing that #1 is the Go executable found in bin. I updated my PATH in Environment to point to this bin folder. I assume at this point I can set #1 to “Find on Path”.
I don’t find a gocode or godef in that bin folder. I do find a godoc and gofmt in there though. I don’t know what gocode and godef are anyway.

I would appreciate any help or tips.

Thanks
-Travis

go get github.com/nsf/gocode
go get code.google.com/p/rog-go/exp/cmd/godef

You have to configure gocode: https://github.com/nsf/gocode, see the readme.

1 Like

Thanks @Defman

I pulled down gocode and taken a look at the gocode README, but I don’t see how I should configure gocode for Komodo.

go get yaks when I try to get godef:

package code.google.com/p/rog-go/exp/cmd/godef: unable to detect version control system for code.google.com/ path

It looks like those files are no longer there. I tried this instead:

go get github.com/rogpeppe/godef

I’m hoping it’s the same thing.

If you have configured gocode (so your GOPATH and other things are properly for gocode), then go to Komodo Preferences and set up gocode and godef binaries. (In my case they are in the $GOPATH/bin/ folder, my $GOPATH is /home/defman/Projects/go and my $PATH contains $GOPATH/bin as well)

Yep, you’re right :smiley:
Btw godef is not necessary, if you won’t use Jump to Definition feature - then you don’t need it.

I expect I will have multiple Golang projects. Can I locate the gocode and godef binaries in with my go binary? Along those lines, I have my GOPATH defined in my project environment vars. Is this a good idea?

It doesn’t make any sense. Your projects must be in the $GOPATH/src/ directory, gocode and godef must be in the $GOPATH/bin/ directory and the rest of things required by any go libraries in the $GOPATH/pkg/ directory.

You must define $GOPATH directory in your profile file (~/.bashrc, ~/.zshrc or ~/.profile) and you should add $GOPATH/bin/ to your $PATH directory if you want Komodo to automatically detect the binaries.

You should follow the structure required by gocode, otherwise it probably won’t work.

/home/defman/Projects/go (=$GOPATH)
├── bin
│   ├── gocode
│   ├── godef
│   ├── % binaries of your projects %
├── pkg
│   └── % compiled dependencies of your projects and some other files %
└── src
    ├── github.com
    │   ├── nsf <- gocode
    │   └── rogpeppe <- godef
    ├── % your project %
    │   └── % content of your project %
    └── % your project %
        └── % content of your project %
    ...
$PATH = ...:/home/defman/Projects/go/bin:...

Thanks @Defman. Clearly I have yet to wrap my brain around Go. I’m used to having my projects be mostly self-contained islands.

I don’t have this use-case, but what do you do if you have dependencies on libraries of different versions? Like if one project needed CoolLibrary 1.0 and a different project needed CoolLibrary 2.0? I noticed in the docs that GOPATH can be concatenated list of paths. When would you want to do that? Would that allow self contained projects?

I don’t know a lot about Go and I can’t say anything about this use-case, I’ve never faced with it because I wrote like 2-3 small programs just to get the basics about Go language. Sorry.

Fair enough.

Thanks for the help.