Structuring Projects

Starting projects:

Run:

go mod init gitlab.com/seanbreckenridge/project_name

when in $GOPATH/src/gitlab.com/seanbreckenridge/project_name

.. to initialize your project properly.

There is no canonical specification for where you put your files/packages.

If:

Making functions start with uppercase automatically exports the function from the package.

To do both a command and a library, you typically have a cmd/package_name/main.go file, which can then be installed from:

go get gitlab.com/seanbreckenridge/project_name/cmd/command_name

.. and installed locally like:

go install ./cmd/command_name

Basic Testing

For basic tests, 9 times out of 10, you want to make the package name for the test file packagename_test, and call it packagename_test.go.

You can use the testing library like:

func TestFunctionName(t* testing.T) {
  packagename.FunctionName()
}

.. and then run go test