Go makes writing robust, powerful software easy. Write it!
- set a
GOPATH
and all your code lives there (echo $GOPATH
) - make sure Go is installed with
go version
- set an alias in your shell to make it easy to hack:
alias golang="cd $GOPATH/src/github.com"
You use go get
to get code. It saves it under GOPATH along with your own code. Try
it with my examples library:
go get -u github.com/anxiousmodernman/examples-go/...
This fetches all packages under this repository. Now you can run something.
cd $GOPATH/src/github.com/anxiousmoderman/examples-go/ctrlc-executable
go build
./ctrlc-executable
NOTE: if you want to "go get" from private repositories, you have to edit your git config in the manner described here: https://gist.github.com/shurcooL/6927554
If you see a library imported, and you don't know how it works. Go to the docs immediately. For
examples, the time
package is used here.
And since this is a built in package you can find it's docs in the standard library docs. Go
is very readable, so don't be afraid to read libraries.
Go is easy to read for humans and easy to parse for computers. The tooling is really good. I recommend Microsoft's
free VS Code editor. After that, you can open any directory from the command line with code .
.
Finally, make sure you install the Go extension. This will automatically download some command line tools.
- Put
$GOPATH/bin
on yourPATH
.export PATH=$PATH:$GOPATH/bin
This is needed because editors look for tools on your PATH to do cool stuff like auto-importing. go build
builds code in the current directory.go install
builds stuff in the current directory, but puts the binary into$GOPATH/bin
. Another good reason to have it on your PATH.