Structuring Projects

Starting projects:


go mod init

when in $GOPATH/src/

.. to initialize your project properly.

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


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

.. 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) {

.. and then run go test