Organize your Go project by placing source code in cmd/ for executables, internal/ for private libraries, and pkg/ for public libraries, with a go.mod file at the root.
myproject/
go.mod
cmd/
myapp/
main.go
internal/
config/
config.go
pkg/
utils/
utils.go
- Initialize the module with
go mod init example.com/myproject. - Create the
cmd/myappdirectory and addmain.goto define your entry point. - Move shared private code into
internal/configto prevent external imports. - Move public library code into
pkg/utilsfor external consumption.