“Go takes documentation seriously” 1
The go official team have developed godoc — a useful documentation tool. This tool parses the source code and formats docstrings and comments into a readable HTML format. This HTML can be read by starting the documentation HTTP server locally. One can use to navigate to function implementation from the documentation
In this guide, I’ll show you how you can get started.
- Install godoc binary
go install http://golang.org/x/tools/cmd/godoc
- If all goes good, the godoc binary should’ve been stored in the
$GOPATH/bin/
- Initialise the $GOPATH environment variable (if not set correctly already)
export GOPATH=$HOME/go
- Now you can go to the folder that you’re working on and run the following command
$GOPATH/bin/godoc -http=:6060
- HTTP server is now running, open
http://localhost:6060
and go through the source code documentation 😊
One can learn to write good documentation for your Go programs using the official guide 2.