BB
bbbmj/golang-template-project
A template for starting new golang projects at Caicloud
Table of Contents generated with DocToc
Golang Template Project
About the project
The template is used to create golang project. All golang projects must follow the conventions in the
template. Calling for exceptions must be brought up in the engineering team.
API docs
The template doesn't have API docs. For web service, please include API docs here, whether it's
auto-generated or hand-written. For auto-generated API docs, you can also give instructions on the
build process.
Design
The template follows project convention doc.
Status
The template project is in alpha status.
See also
Getting started
Below we describe the conventions or tools specific to golang project.
Layout
├── .github
│ ├── ISSUE_TEMPLATE.md
│ └── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .golangci.yml
├── CHANGELOG.md
├── Makefile
├── OWNERS
├── README.md
├── build
│ ├── admin
│ │ └── Dockerfile
│ └── controller
│ └── Dockerfile
├── cmd
│ ├── admin
│ │ └── admin.go
│ └── controller
│ └── controller.go
├── docs
│ └── README.md
├── hack
│ ├── README.md
│ ├── deployment.yaml
│ └── script.sh
├── pkg
│ ├── apis
│ │ └── v1
│ │ └── README.md
│ ├── utils
│ │ └── net
│ │ └── net.go
│ └── version
│ └── version.go
├── release
│ ├── template-admin.yaml
│ └── template-controller.yaml
├── test
│ ├── README.md
│ └── test_make.sh
├── third_party
│ └── README.md
└── vendor
└── README.md
A brief description of the layout:
.githubhas two template files for creating PR and issue. Please see the files for more details..gitignorevaries per project, but all projects need to ignorebindirectory..golangci.ymlis the golangci-lint config file.Makefileis used to build the project. You need to tweak the variables based on your project.CHANGELOG.mdcontains auto-generated changelog information.OWNERScontains owners of the project.README.mdis a detailed description of the project.binis to hold build outputs.cmdcontains main packages, each subdirecoty ofcmdis a main package.buildcontains scripts, yaml files, dockerfiles, etc, to build and package the project.docsfor project documentations.hackcontains scripts used to manage this repository, e.g. codegen, installation, verification, etc.pkgplaces most of project business logic and locateapipackage.releasechart for production deployment.testholds all tests (except unit tests), e.g. integration, e2e tests.third_partyfor all third party libraries and tools, e.g. swagger ui, protocol buf, etc.vendorcontains all vendored code.
Notes
- Makefile MUST NOT change well-defined command semantics, see Makefile for details.
- Every project MUST use
depfor vendor management and MUST checkinvendordirecotry. cmdandbuildMUST have the same set of subdirectories for main targets- For example,
cmd/admin,cmd/controllerandbuild/admin,build/controller. - Dockerfile MUST be put under
builddirectory even if you have only one Dockerfile.
- For example,