better-go
go-template
Go

boilerplate, golang project starter tool, support go-zero/go-micro/gin

Last updated Jan 16, 2026
96
Stars
7
Forks
3
Issues
0
Stars/day
Attention Score
8
Language breakdown
Go 37.3%
Shell 27.0%
HCL 19.4%
Makefile 9.9%
Python 6.6%
โ–ธ Files click to expand
README

English | ็ฎ€ไฝ“ไธญๆ–‡

go-template

  • [x] boilerplate, go project starter with go-zero/gin/go-micro.
  • [x] go microservice (go-zero/gin/go-micro) project directory generation tool/scaffold.
  • [x] Implementation based on cookiecutter.

Feature:

  • [x] mono repo: support creating mono repo, the git project root directory.
- [x] go-zero - [x] go-kratos - [x] gin - [x] go-micro - [x] [rs]() : rust monorepo
  • [x] single app: support creating single app, a single microservice directory.
- [x] go-zero - [x] gin - [x] go-micro
  • [x] can be used individually or in combination
  • [x] usage:
- [x] Create the mono-repo root directory first - [x] Switch to app/, create single app single microservice directory.

Development Roadmap:

  • [x] https://github.com/better-go/cookiecutter-go/projects/1

Intro:

  • go-zero microservice:
- [x] Integrate air tool, watch project code, automatic compilation + hot reload, make go development smoother (like Python/Js) - [x] rpc: integrated grpc - [x] log: integrated uber log - [x] db: integrate gorm + mysql - [x] cache: integrate redis - [x] mq: integrate rabbitmq - [x] Service Discovery: Integrate etcd - [x] cronjob: integrate cronjob
  • go-kratos microservice:
- [x] Integrate go-kratos scaffolding built-in components - [x] integrated air tool - [x] integrated grpc/http
  • gin microservice:
- [x] Integrate air tool, watch project code, automatic compilation + hot reload, make go development smoother (like Python/Js) - [x] rpc: integrated grpc - [x] log: integrated uber log - [x] db: integrate gorm + mysql - [x] cache: integrate redis - [x] mq: integrate rabbitmq - [x] Service Discovery: Integrate etcd - [x] cronjob: integrate cronjob
  • go-micro microservice:
- [x] Integrate air tool, watch project code, automatic compilation + hot reload, make go development smoother (like Python/Js) - [x] rpc: integrated grpc - [x] log: integrated uber log - [x] db: integrate gorm + mysql

User Case:

  • [x] https://github.com/zeromicro/zeromall
- Microservice B2B2C e-commerce platform based on go-zero

Quick Start:

Install:

  • https://cookiecutter.readthedocs.io/en/1.7.2/installation.html
# Mac OS X install cookiecutter:
brew install cookiecutter

Python + pipx:

brew install pipx pipx ensurepath pipx install cookiecutter

Debian/Ubuntu:

sudo apt-get install cookiecutter

Best Practice:

  • [x] choice 1: create mono-repo + single-app
- support templates: - go-zero - gin - go-micro
  • [x] choice 2: create library-repo

1. Mono-Repo + Single-App

  • 1.1 create mono repo:
git repo / project root.
>
Elevate according to command line parameters, gradually create.
cd your-workspace/

In the current directory, create the root directory of the go-zero mono repo project

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="mono-repo/go-zero"

In the current directory, create the gin mono repo project root directory

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="mono-repo/gin"

In the current directory, create the root directory of the go-micro mono repo project

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="mono-repo/go-micro"
  • 1.2 create single app folder:
cd your-mono-repo-app-create-root/

In the current directory, create a microservice directory: use go-zero

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="single-app/go-zero"

In the current directory, create a microservice directory: use gin

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="single-app/gin"

In the current directory, create a microservice directory: use go-micro

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="single-app/go-micro"
  • tips:
- Path parameters, do not add suffix : / - If gomodulename is different from projectfoldername, be careful not to pass it wrong.

2. create library repo:

  • library-repo
cd your-workspace/

In the current directory, create the mono repo project root directory:

cookiecutter https://github.com/better-go/cookiecutter-go.git --directory="library-repo"

Generate Project Folder Structure:

  • [x] Mono Repo:
  • Brief description of directory structure: a quick look of the overall directory.
-> % tree . -L 3
.
โ”œโ”€โ”€ app
โ”‚ โ”œโ”€โ”€ basic // Basic services: usually business-agnostic
โ”‚ โ”‚ โ”œโ”€โ”€ demo // Example:
โ”‚ โ”‚ โ””โ”€โ”€ user // user management:
โ”‚ย  โ”œโ”€โ”€ biz // Business Services: Segmentation according to business
โ”‚ โ”‚ โ””โ”€โ”€ member // Member service:
โ”‚ โ”‚ โ””โ”€โ”€ order // order service:
โ”‚ โ”‚ โ””โ”€โ”€ cart // Shopping cart service:
โ”‚ โ””โ”€โ”€ std // Unified definition within the business:
โ”‚ โ”œโ”€โ”€ proto // Unified definition of business status code
โ”œโ”€โ”€ deploy // deployment script, service orchestration
โ”‚ย ย  โ”œโ”€โ”€ local
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Makefile
โ”‚ย ย  โ””โ”€โ”€ staging
โ”‚ย ย      โ””โ”€โ”€ Makefile
โ”œโ”€โ”€ infra // infrastructure
โ”‚ย ย  โ””โ”€โ”€ tool
โ””โ”€โ”€ pkg // Utility code base accumulated by the project, not related to business
  • Detailed description of directory structure:
-> % tree . -L 6
.
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ README.MD
โ”œโ”€โ”€ app
โ”‚ โ”œโ”€โ”€ basic // Basic service unit 1: general services unrelated to user management/push/SMS/etc.
โ”‚ โ”‚ โ”œโ”€โ”€ demo // Example of a single microservice:
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ cmd // Single-service startup entry: including multiple startup methods:
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ main.go                         // api server, grpc server, job server, admin server ๅฏๅŠจ
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ configs // External middleware configuration items: db, cache, mq, etc.
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ configs.toml
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ docs // single-service documentation
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ internal // business logic (not exposed)
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ dao // data layer read/write
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ cache // cache r/w
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ db                          //      db crud
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ http // Call http api outside this service
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ meta.go // dao resource convergence
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ mq                          //      mq r/w
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ rpc // call rpc(gRPC) api outside this service
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ domain // In-service business split:
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ demo // Business Unit 1 / Business Unit 2
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ service // API convergence layer (external convergence internal logic, exposed API: grpc/http/job/admin)
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ service.go
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ proto // Data definition layer: (exposed to the outside world)
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ api // grpc + http api definition
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ api.proto
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ config // config toml mapping model
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ config.proto
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ model // internal model
Model โ”‚ โ”‚ โ””โ”€โ”€ model.proto
โ”‚ โ”‚ โ””โ”€โ”€ user // Basic service 2:
โ”‚ โ”‚ โ”œโ”€โ”€ identity // within the service
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ Makefile
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ cmd
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ main.go
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ configs
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ configs.toml
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ docs
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ internal
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ dao
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ domain
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ service
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ proto
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ api
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ config
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ model
โ”‚ย ย  โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ readme.md
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ readme.md
โ”‚ โ”œโ”€โ”€ biz // Specific business unit:
โ”‚ โ”‚ โ”‚โ”€โ”€ member // Member service
โ”‚ย ย  โ”‚ย ย  โ”‚   โ””โ”€โ”€ cmd
โ”‚ย ย  โ”‚ย   โ”‚       โ””โ”€โ”€ main.go
โ”‚ โ”‚ โ””โ”€โ”€ order // order service
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ cmd
โ”‚ย ย  โ”‚ย ย          โ””โ”€โ”€ main.go
โ”‚ โ””โ”€โ”€ std // Unified definition within the project business (business status code, business error msg number)
โ”‚ย ย      โ”œโ”€โ”€ Makefile
โ”‚ย ย      โ”œโ”€โ”€ proto
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ config
โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ config.proto
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ error
โ”‚ โ”‚ โ””โ”€โ”€ code.proto // business status code
โ”‚ย ย      โ””โ”€โ”€ readme.md
โ”œโ”€โ”€ deploy // Deploy related scripts: dockerfile etc.
โ”‚ย ย  โ”œโ”€โ”€ local
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Makefile
โ”‚ย ย  โ””โ”€โ”€ staging
โ”‚ย ย      โ””โ”€โ”€ Makefile
โ”œโ”€โ”€ go.mod
โ”œโ”€โ”€ go.sum
โ”œโ”€โ”€ infra // Plugin dependent services: cli, middleware, etc.
โ”‚ย ย  โ””โ”€โ”€ tool
โ””โ”€โ”€ pkg // Utility code base gradually accumulated in the project

46 directories, 24 files

  • [x] single app:
-> % tree -L 3 ./single-app/{{cookiecutter.app_name}}
./single-app/{{cookiecutter.app_name}}
โ”œโ”€โ”€ cmd
โ”‚ย ย  โ””โ”€โ”€ main.go
โ”œโ”€โ”€ configs
โ”‚ย ย  โ””โ”€โ”€ configs.toml
โ”œโ”€โ”€ internal
โ”‚ย ย  โ””โ”€โ”€ dao
โ”‚ย ย      โ””โ”€โ”€ db
โ”œโ”€โ”€ proto
โ”‚ย ย  โ””โ”€โ”€ api
โ”‚ย ย      โ””โ”€โ”€ api.go
โ””โ”€โ”€ readme.md

7 directories, 4 files

Call link description:

  • Code call link description: Take the app/basic/demo service as an example (top-down call)
- Cmd startup entry: app/basic/demo/cmd/main.go - Service ๅ…ฅๅฃ: app/basic/demo/internal/service/service.go - External API Gateway: app/basic/demo/internal/service/outer/outer.go - Inbound RPC gateway: app/basic/demo/internal/service/inner/inner.go - Internal Admin API Gateway: app/basic/demo/internal/service/admin/admin.go - Internal Job Gateway: app/basic/demo/internal/service/job/job.go - Proto data definition: --API layers: app / basic / demo / proto / api / api.proto - Config ๅฑ‚: app/basic/demo/proto/config/config.proto - Model ๅฑ‚: app/basic/demo/proto/model/model.proto - Router route registration: app/basic/demo/internal/router/router.go - Domain business areas: - A business unit: app/basic/demo/internal/domain/demo/demo.go - Dao data layer operations: - Meta aggregation (convergence of Dao layer resources): app/basic/demo/internal/dao/meta.go - DB ๅฑ‚: app/basic/demo/internal/dao/db/db.go - Cache ๅฑ‚: app / basic / demo / internal / dao / cache / cache.go

User Manual:

  • [x] https://github.com/better-go/cookiecutter-go/wiki/manual
  • [x] Initialize the microservice directory, how to use it.

Reference:

  • [x] https://github.com/better-go/cookiecutter-go/wiki/reference

Contributors:

Henry.Huang/
Henry.Huang
Ferris/
Ferris
Mourad
Mourad Maatoug
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท better-go/go-template ยท Updated daily from GitHub