Go Work Environment
This lesson addresses how compilation looks in the background, what a workspace is and what the basic folder structure of a Go environment is.
Workspace #
A folder structure with two directories at its root is typically is called a workspace. A typical Golang project keeps all its code in a single workspace. The workspace of Golang is:
- src, a folder that contains Go source code files
- bin, a folder that contains executable binaries (also called commands)
However, if you need external packages, there will also be a folder called pkg to accommodate these.
GOPATH variable
The workspace root location cannot be the same as the Go install location, and it is specified by the GOPATH environment variable. It is by default a go subfolder in the home directory, so $HOME/go on Unix or C:\Users\username\go on Windows. Add the bin folder of your workspace to the PATH variable so that your application binaries are automatically found. For example on Linux add the following to your .profile:
export GOPATH=$HOME/go # this is the default
export PATH=$PATH:$GOPATH/bin
...