To get started on a throw-away project (that will never be published &c.):
go mod init temp
At that point, go get, go build and the rest will be “module aware”, and you can play around without needing to worry about go-path and the global go-workspace.
For a real project:
# Pick your source-host here
go mod init gitlab.com/group/project
is enough.
If you’re maintaining multiple Go packages in a single Git repo, the typical approach is to create a module at the repo-root. The Go tooling is smart-enough to use the local version of all packages within the module (even if you’re using a fully-qualified import).
I’m bad at this, at the tooling feels un-natural every time I do it. So - read the references.
When all else fails, you can delete all of the require statements from your go.mod, delete your go.sum file, re-do go mod tidy and see what’s different.
Tests for the file foo.go should live in foo_test.go.
Example:
package yourPackage
import "testing"
func TestAThing(t *testing.T) {
.Errorf("A failure!")
t}
Run the tests with go test.