Setting up a project as a mono repo, with public and private packages.
See https://github.com/golang-standards/project-layout for a much more detail!
In the following commands replace my-project for your projects name, and kgolding with you git username.
-
On github or gitlab create a new empty repo e.g.
github.com/kgolding/my-projectfor this example. -
mkdir my-project -
cd my-project -
mkdir -p cmd/app pkg internal && touch README.md && touch cmd/app/main.go -
go mod init github.com/kgolding/my-project -
You should now have the following structure:
├── cmd │ └── app │ └── main.go ├── go.mod ├── internal ├── pkg └── README.md -
git init -
git add . -
git commit -m "initial commit" -
git remote add origin git@github.com:kgolding/my-project.git -
git push -u origin master
| Relative path | Description |
|---|---|
| ./ | The root of the git repo |
| ./README.md | The projects main readme |
| ./go.mod | Created by running go mod github.com/kgolding.go-app-structure |
| ./cmd/* | Folders for each build-able application main.go |
| ./internal/* | Folders for each private package (that can not be used in other projects) |
| ./pkg/* | Folders for each public package (that might be used in other projects) |
| ./vendor/* | Optional: External dependencies as populated by go mod vendor |