Initialise with go mod init github.com/willdollman/project-name
How to structure a Go project? · vsupalov.com seems like a reasonable summary and acknowledges that things have changed since the introduction of Go modules.
Standard Package Layout has some good ideas about how this should work.
Essentially the root package contains high-level "domain" types which can be implemented by other packages which work like interchangeable components.
This can be tricky when starting out, as there are lots of small, easy-to-make mistakes.
Some debugging suggestions/mistakes I've made:
go mod init
, and the import path you're using matches go.mod
.newpackage.Method()
in your code - the newpackage
name is required.internal/
, make sure your import path includes it (though gopls should add it automatically). E.g. github.com/willdollman/project-name/internal/module/path
.