Monday, March 17, 2014

Godoc is Missing; Another GoLang Adventure

I was working through some Go tutorials and it told me that Go was kind of self documenting using godoc. I tried their example and discovered that the executable wasn't found.

It turns out that in Go 1.2, if you installed from source, godoc is missing. From what I can piece together from searches online the install-from-binary packages include godoc, but the source doesn't; also as of 1.2 godoc was split so the binary is separated from its source and package information. Still want godoc? Here's how you can get it.

First, you need to have $GOROOT and $GOPATH set. You can do this at the command line, which will only last for your session, or you can add it to one of your environment files like .bash_profile or .bashrc so it persists over logins.

export GOROOT=`go env GOROOT`
export PATH=$PATH:$GOROOT/bin

This assumes you already set your GOROOT variable. You can use the above method to set your GOPATH if the environment variable is already set (hint: go env GOPATH shouldn't return a blank line; if it does, you need to use your workspace path after the equals sign. Also, GOPATH cannot match GOROOT. That would be bad. Side note, Go won't allow it anyway.)

Time to get godoc.

go get code.google.com/p/go.tools/cmd/godoc

This installed the binary to my GOROOT/bin directory, adding it to the binaries for the compiler. Godoc's source and package files are stored in GOPATH/src.

It's kind of strange if you're not accustomed to the Go conventions style...but if you want godoc, this is how you can get it installed!

No comments:

Post a Comment