Go has extensive online documentation and coding standards. Setting up your editor to run
go fmt on save is all that is necessary to be compliant with coding standards.
Vokal maintains a Go starter project on GitHub to get you started.
Go has good install instructions for all platforms.
All your Go code will live in a user-defined root directory called the
GOPATH; this is by convention usually called
go. Create a directory structure with the git project root inside a folder named
src which is contained by what will be the root of your go environment. All your code—including dependencies installed via
go get—will live as a subdirectory of the
go |-bin (compiled binaries live here) |-pkg (platform-specific compiled libraries live here) |-src (all your Go source code goes here) |-git project folder
It is optional, but recommended, that you add the
bin directory to your
PATH environment variable. This allows use of
go install to build an executable binary of your program and have it easily started from anywhere.
$ export PATH=$PATH:$GOPATH/bin
Install dependencies, including test dependencies:
$ go get $ go get -t
See if tests pass; with optional verbose output:
$ go test -v
Generate test coverage:
$ go test -v -coverprofile=coverage.txt -covermode=count
In the event you are running a project that uses
docker-compose to build the code inside a Docker container, here is a quick guide to getting a project and its tests running:
$ docker-compose up $ docker exec -it <projectcontainer> bash > go test -v
For those using Vagrant, the steps are slightly different.
Open console and enter the git project folder:
$ vagrant ssh $ cd /vagrant/src/[git project folder] $ docker-compose up
Then, open a new console and enter the git project folder:
$ vagrant ssh $ cd /vagrant/src/[git project folder] $ export GOPATH=/vagrant/
Go has web-based “playgrounds” to experiment with code ideas. This tool sends the code to a server, where it is compiled, run, and the results returned. Because of the speed of Go, however, you can effectively use it like an interactive interpreter. Further, you can generate a code sample and share it in a playground, similar to a GitHub gist.
Also, there is an interactive Go tutorial that uses playgrounds to walk you through examples covering most of the basics of the language. It's highly recommended to start here before digging into various books, blogs, or other resources.