Environment | Go
Go Environment#
$GOPATH#
Go is opinionated.
By convention, all Go code lives within a single workspace (folder). This workspace could be anywhere in your machine. If you don't specify, Go will assume $HOME/go as the default workspace. The workspace is identified (and modified) by the environment variable GOPATH.
You should set the environment variable so that you can use it later in scripts, shells, etc.
Update your .bash_profile to contain the following exports:
Note you should open a new shell to pickup these environment variables.
Go assumes that your workspace contains a specific directory structure.
Go places its files in three directories: All source code lives in src, package objects lives in pkg, and the compiled programs live in bin. You can create these directories as follows:
At this point you can go get and the src/package/bin will be installed correctly in the appropriate $GOPATH/xxx directory.
Go Vet#
go vet
Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string. Vet uses heuristics that do not guarantee all reports are genuine problems, but it can find errors not caught by the compilers.
Remember to use go vet in your build scripts as it can alert you to some subtle bugs in your code before they hit your poor users.