{"id":13757682,"url":"https://github.com/better-go/go-template","last_synced_at":"2025-04-14T12:42:39.466Z","repository":{"id":37892451,"uuid":"268551187","full_name":"better-go/go-template","owner":"better-go","description":"boilerplate, golang project starter tool, support go-zero/go-micro/gin","archived":false,"fork":false,"pushed_at":"2023-02-24T23:03:50.000Z","size":231,"stargazers_count":92,"open_issues_count":3,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T01:53:28.253Z","etag":null,"topics":["boilerplate","cli","cookiecutter","cookiecutter-template","gin","go-micro","go-zero","golang","microservice","monorepo","skeleton","starter"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/better-go.png","metadata":{"files":{"readme":"readme-cn.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-06-01T14:52:24.000Z","updated_at":"2025-03-07T14:51:13.000Z","dependencies_parsed_at":"2024-01-17T16:08:24.162Z","dependency_job_id":"1b0a87fa-bd2e-4d7e-9125-0b163c0485a5","html_url":"https://github.com/better-go/go-template","commit_stats":{"total_commits":100,"total_committers":5,"mean_commits":20.0,"dds":"0.050000000000000044","last_synced_commit":"7b93e32a5f01e8c86191a9706a228e87baa220bf"},"previous_names":["better-go/cookiecutter-go"],"tags_count":4,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/better-go%2Fgo-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/better-go%2Fgo-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/better-go%2Fgo-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/better-go%2Fgo-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/better-go","download_url":"https://codeload.github.com/better-go/go-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248883202,"owners_count":21177175,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boilerplate","cli","cookiecutter","cookiecutter-template","gin","go-micro","go-zero","golang","microservice","monorepo","skeleton","starter"],"created_at":"2024-08-03T12:00:44.833Z","updated_at":"2025-04-14T12:42:39.425Z","avatar_url":"https://github.com/better-go.png","language":"Go","funding_links":[],"categories":["Libraries that use [go-zero](https://github.com/tal-tech/go-zero)"],"sub_categories":[],"readme":"# go-template\n\n- [x] boilerplate, go project starter with `go-zero/gin/go-micro`.\n- [x] go 微服务(`go-zero/gin/go-micro`)项目目录生成工具/脚手架.\n- [x] 基于 [cookiecutter](https://github.com/cookiecutter/cookiecutter) 实现.\n\n## Feature:\n\n- [x] `mono repo`: 支持创建 `mono repo`, git 项目根目录.\n    - [x] [go-zero](https://github.com/tal-tech/go-zero)\n    - [x] [go-kratos](https://github.com/go-kratos/kratos)\n    - [x] [gin](https://github.com/gin-gonic/gin)\n    - [x] [go-micro](https://github.com/asim/go-micro)\n    - [x] [rs]() : rust monorepo\n- [x] `single app`: 支持创建 `single app`, 单个微服务目录.\n    - [x] [go-zero](https://github.com/tal-tech/go-zero)\n    - [x] [gin](https://github.com/gin-gonic/gin)\n    - [x] [go-micro](https://github.com/asim/go-micro)\n- [x] 可单个使用, 也可同时组合使用\n- [x] usage:\n    - [x] 先创建 `mono-repo` 根目录\n    - [x] 切换到 `app/` 下, 创建 `single app` 单个微服务目录.\n\n## Development Roadmap:\n\n- [x] https://github.com/better-go/cookiecutter-go/projects/1\n\n### Intro:\n\n- `go-zero` 微服务:\n    - [x] 集成 [air](https://github.com/cosmtrek/air) 工具, watch 项目代码, `自动编译 + hot reload`, 让 go 开发更丝滑(类 Python/Js)\n    - [x] rpc: 集成 grpc\n    - [x] log: 集成 uber log\n    - [x] db: 集成 gorm + mysql\n    - [x] cache: 集成 redis\n    - [x] mq: 集成 rabbitmq\n    - [x] 服务发现: 集成 etcd\n    - [x] cronjob: 集成 cronjob\n- `go-kratos` 微服务:\n    - [x] 集成 `go-kratos` 脚手架自带组件\n    - [x] 集成 air 工具\n    - [x] 集成 grpc/http\n- `gin` 微服务:\n    - [x] 集成 [air](https://github.com/cosmtrek/air) 工具, watch 项目代码, `自动编译 + hot reload`, 让 go 开发更丝滑(类 Python/Js)\n    - [x] rpc: 集成 grpc\n    - [x] log: 集成 uber log\n    - [x] db: 集成 gorm + mysql\n    - [x] cache: 集成 redis\n    - [x] mq: 集成 rabbitmq\n    - [x] 服务发现: 集成 etcd\n    - [x] cronjob: 集成 cronjob\n- `go-micro` 微服务:\n    - [x] 集成 [air](https://github.com/cosmtrek/air) 工具, watch 项目代码, `自动编译 + hot reload`, 让 go 开发更丝滑(类 Python/Js)\n    - [x] rpc: 集成 grpc\n    - [x] log: 集成 uber log\n    - [x] db: 集成 gorm + mysql\n\n## User Case:\n\n- [x] https://github.com/zeromicro/zeromall\n    - 基于 go-zero 的微服务`B2B2C电商平台`\n\n## Quick Start:\n\n### Install:\n\n- https://cookiecutter.readthedocs.io/en/1.7.2/installation.html\n\n```bash\n\n# Mac OS X 安装 cookiecutter:\nbrew install cookiecutter\n\n# Python + pipx:\nbrew install pipx\npipx ensurepath\npipx install cookiecutter\n\n# Debian/Ubuntu:\nsudo apt-get install cookiecutter\n\n```\n\n### Best Practice:\n\n- [x] choice 1: create `mono-repo` + `single-app`\n    - support templates:\n        - `go-zero`\n        - `gin`\n        - `go-micro`\n- [x] choice 2: create `library-repo`\n\n#### 1. Mono-Repo + Single-App\n\n- 1.1 create `mono repo`:\n\n\u003e git repo / project root.\n\u003e\n\u003e 根据命令行参数提升, 逐步创建.\n\n```bash\n\ncd your-workspace/\n\n# 在当前目录下, 创建 go-zero mono repo 项目根目录\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"mono-repo/go-zero\"\n\n\n# 在当前目录下, 创建 gin mono repo 项目根目录\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"mono-repo/gin\"\n\n\n# 在当前目录下, 创建 go-micro mono repo 项目根目录\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"mono-repo/go-micro\"\n\n\n\n```\n\n- 1.2 create `single app` folder:\n\n```bash\n\ncd your-mono-repo-app-create-root/\n\n# 在当前目录下, 创建微服务目录: 使用 go-zero\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"single-app/go-zero\"\n\n# 在当前目录下, 创建微服务目录: 使用 gin\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"single-app/gin\"\n\n# 在当前目录下, 创建微服务目录: 使用 go-micro\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"single-app/go-micro\"\n\n\n\n```\n\n- tips:\n    - 路径参数, 不要添加后缀 : `/`\n    - `go_module_name` 如果 和 `project_folder_name` 不同, 要注意不要传错.\n\n#### 2. create library repo:\n\n- `library-repo`\n\n```bash\n\ncd your-workspace/\n\n# 在当前目录下, 创建mono repo 项目根目录:\ncookiecutter https://github.com/better-go/cookiecutter-go.git --directory=\"library-repo\"\n\n```\n\n## Generate Project Folder Structure:\n\n- [x] Mono Repo:\n\n\n- 目录结构简略说明: 对整体目录的 quick look.\n\n```html\n-\u003e % tree . -L 3\n.\n├── app\n│   ├── basic            // 基础服务: 通常是业务无关的\n│   │   ├── demo         //     示例:\n│   │   └── user         //     用户管理:\n│   ├── biz              // 业务服务: 根据业务切分\n│   │   └── member       //     会员服务:\n│   │   └── order        //     订单服务:\n│   │   └── cart         //     购物车服务:\n│   └── std              // 业务内统一定义:\n│       ├── proto        //     统一定义业务状态码\n├── deploy               // 部署脚本, 服务编排\n│   ├── local\n│   │   └── Makefile\n│   └── staging\n│       └── Makefile\n├── infra                // 基础设施\n│   └── tool\n└── pkg                  // 项目积累的 utility 代码库, 与业务无关\n```\n\n- 目录结构详细说明:\n\n```html\n-\u003e % tree . -L 6\n.\n├── LICENSE\n├── Makefile\n├── README.MD\n├── app\n│   ├── basic                                       // 基础服务单元1 : 用户管理/推送/短信/等业务无关的通用服务\n│   │   ├── demo                                    // 单个微服务示例:\n│   │   │   ├── cmd                                 //      单服务启动入口: 包含 多个启动方式:\n│   │   │   │   └── main.go                         // api server, grpc server, job server, admin server 启动\n│   │   │   ├── configs                             //      外部中间件配置项: db,缓存,mq 等\n│   │   │   │   └── configs.toml\n│   │   │   ├── docs                                // 单服务自身文档\n│   │   │   ├── internal                            //      业务逻辑(不对外暴露)\n│   │   │   │   ├── dao                             //      数据层 read/write\n│   │   │   │   │   ├── cache                       //      缓存 r/w\n│   │   │   │   │   ├── db                          //      db crud\n│   │   │   │   │   ├── http                        //      调用本服务之外的 http api\n│   │   │   │   │   ├── meta.go                     //      dao 资源收敛\n│   │   │   │   │   ├── mq                          //      mq r/w\n│   │   │   │   │   └── rpc                         //      调用本服务之外的 rpc(gRPC) api\n│   │   │   │   ├── domain                          // 服务内业务拆分:\n│   │   │   │   │   └── demo                        //      业务单元1 / 业务单元2\n│   │   │   │   └── service                         // API 收敛层(对外收敛内部逻辑, 暴露 API: grpc/http/job/admin)\n│   │   │   │       └── service.go\n│   │   │   └── proto                               // 数据定义层: (可对外暴露)\n│   │   │       ├── api                             //      grpc + http api 定义\n│   │   │       │   └── api.proto\n│   │   │       ├── config                          //      config toml 映射 model\n│   │   │       │   └── config.proto\n│   │   │       └── model                           //      内部 model\n│   │   │           └── model.proto\n│   │   └── user                                    // 基础服务2:\n│   │       ├── identity                            //   服务内\n│   │       │   ├── Makefile\n│   │       │   ├── cmd\n│   │       │   │   └── main.go\n│   │       │   ├── configs\n│   │       │   │   └── configs.toml\n│   │       │   ├── docs\n│   │       │   ├── internal\n│   │       │   │   ├── dao\n│   │       │   │   ├── domain\n│   │       │   │   └── service\n│   │       │   ├── proto\n│   │       │   │   ├── api\n│   │       │   │   ├── config\n│   │       │   │   └── model\n│   │       │   └── readme.md\n│   │       └── readme.md\n│   ├── biz                                         // 具体业务单元:\n│   │   │── member                                  // 会员服务\n│   │   │   └── cmd\n│   │   │       └── main.go\n│   │   └── order                                   // 订单服务\n│   │       └── cmd\n│   │           └── main.go\n│   └── std                                        // 项目业务内统一定义(业务状态码, 业务出错 msg 编号)\n│       ├── Makefile\n│       ├── proto\n│       │   ├── config\n│       │   │   └── config.proto\n│       │   └── error\n│       │       └── code.proto                     // 业务状态码\n│       └── readme.md\n├── deploy                                         // 部署相关脚本: dockerfile 等\n│   ├── local\n│   │   └── Makefile\n│   └── staging\n│       └── Makefile\n├── go.mod\n├── go.sum\n├── infra                                          // 插件依赖服务: cli, 中间件等\n│   └── tool\n└── pkg                                            // 项目中逐步积累的 utility 代码库\n\n46 directories, 24 files\n```\n\n- [x] single app:\n\n```bash\n\n-\u003e % tree -L 3 ./single-app/{{cookiecutter.app_name}}\n./single-app/{{cookiecutter.app_name}}\n├── cmd\n│   └── main.go\n├── configs\n│   └── configs.toml\n├── internal\n│   └── dao\n│       └── db\n├── proto\n│   └── api\n│       └── api.go\n└── readme.md\n\n7 directories, 4 files\n\n\n```\n\n## 调用链路说明:\n\n- 代码调用链路说明: 以 `app/basic/demo` 服务为例(自顶向下调用)\n    - Cmd 启动入口: `app/basic/demo/cmd/main.go`\n    - Service 入口: `app/basic/demo/internal/service/service.go`\n        - 对外 API 网关: `app/basic/demo/internal/service/outer/outer.go`\n        - 对内 RPC 网关: `app/basic/demo/internal/service/inner/inner.go`\n        - 对内 Admin API 网关: `app/basic/demo/internal/service/admin/admin.go`\n        - 对内 Job 网关: `app/basic/demo/internal/service/job/job.go`\n    - Proto 数据定义:\n        - API 层: `app/basic/demo/proto/api/api.proto`\n        - Config 层: `app/basic/demo/proto/config/config.proto`\n        - Model 层: `app/basic/demo/proto/model/model.proto`\n    - Router 路由注册: `app/basic/demo/internal/router/router.go`\n    - Domain 业务领域:\n        - 某业务单元: `app/basic/demo/internal/domain/demo/demo.go`\n    - Dao 数据层操作:\n        - Meta 聚合(收敛 Dao 层资源): `app/basic/demo/internal/dao/meta.go`\n        - DB 层: `app/basic/demo/internal/dao/db/db.go`\n        - Cache 层: `app/basic/demo/internal/dao/cache/cache.go`\n\n## User Manual:\n\n- [x] https://github.com/better-go/cookiecutter-go/wiki/manual\n- [x] 初始化好微服务目录, 如何使用.\n\n## Reference:\n\n- [x] https://github.com/better-go/cookiecutter-go/wiki/reference\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetter-go%2Fgo-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetter-go%2Fgo-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetter-go%2Fgo-template/lists"}