boilerplate, golang project starter tool, support go-zero/go-micro/gin
English | 简体中文
go-zero/gin/go-micro
.go-zero/gin/go-micro
) project directory generation tool/scaffold.mono repo
: support creating mono repo
, the git project root directory.
single app
: support creating single app
, a single microservice directory.
mono-repo
root directory firstapp/
, create single app
single microservice directory.go-zero
microservice:
automatic compilation + hot reload
, make go development smoother (like Python/Js)go-kratos
microservice:
go-kratos
scaffolding built-in componentsgin
microservice:
automatic compilation + hot reload
, make go development smoother (like Python/Js)go-micro
microservice:
automatic compilation + hot reload
, make go development smoother (like Python/Js)B2B2C e-commerce platform
based on go-zero
# 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
mono-repo
+ single-app
go-zero
gin
go-micro
library-repo
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"
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"
/
go_module_name
is different from project_folder_name
, be careful not to pass it wrong.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"
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
-> % 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
-> % 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
app/basic/demo
service as an example (top-down call)
app/basic/demo/cmd/main.go
app/basic/demo/internal/service/service.go
app/basic/demo/internal/service/outer/outer.go
app/basic/demo/internal/service/inner/inner.go
app/basic/demo/internal/service/admin/admin.go
app/basic/demo/internal/service/job/job.go
app / basic / demo / proto / api / api.proto
app/basic/demo/proto/config/config.proto
app/basic/demo/proto/model/model.proto
app/basic/demo/internal/router/router.go
app/basic/demo/internal/domain/demo/demo.go
app/basic/demo/internal/dao/meta.go
app/basic/demo/internal/dao/db/db.go
app / basic / demo / internal / dao / cache / cache.go
Henry.Huang |
Ferris |
Mourad Maatoug |