Tags: #go #project
This information was copied from an older article, which didn’t cover Go Modules.
https://www.digitalocean.com/community/tutorials/understanding-the-gopath
Inside of a Go Workspace, or GOPATH
, there are three directories: bin
, pkg
, and src
. Each of these directories has special meaning to the Go tool chain.
The $GOPATH/bin
directory is where Go places binaries that go install
compiles. Our operating system uses the $PATH
environment variable to find binary applications that can execute without a full path. It is recommended to add this directory to our global $PATH
variable.
The $GOPATH/pkg
directory is where Go stores pre-compiled object files to speed up subsequent compiling of programs. Typically, most developers won’t need to access this directory. If you experience issues with compilation, you can safely delete this directory and Go will then rebuild it.
The src
directory is where all of our .go
files, or source code, must be located (pre 1.13 when go modules were introduced!). This shouldn’t be confused with the source code the Go tooling uses, which is located at the $GOROOT
. As we write Go applications, packages, and libraries, we will place these files under $GOPATH/src/path/to/code
.
In order of priority:
† https://github.com/golang-standards/project-layout/issues/117
One of the Google Go authors states:
For the record, the minimal standard layout for an importable Go repo is really:
LICENSE
file in your rootgo.mod
file in your rootThat’s it. That’s the “standard”.
In particular:
The importable golang.org/x
repos break every one of these “rules”.