领域模块化单体 monorepo 模板(Go 1.27 / Gin):modules/ 领域模块 + 三端口(user/admin/openapi)
- cron + consumer + 一次性命令;模块经 mooth 脚手架一键生成。
git clone --depth=1 -b main https://github.com/gomooth/quick-server-template.git server-api
cd server-api
rm -rf .git
git init
git checkout -b main
git remote add origin your_url
git add .
git commit -m "init"
git push -u origin mainmake hooks # 可选:启用 pre-commit 本地闸(goimports/vet/单测档)
make build # 本地编译,产物 main
make build:linux # Linux 发行版(upx 压缩,产物入 .dist)./main # 全部形态(三端口 + cron + consumer)
./main -mode=user # 仅用户端端口 :8000
./main -mode=admin # 仅管理端端口 :8001(可仅内网部署)
./main -mode=openapi # 仅三方开放面 :8002
./main -mode=cronjob # 仅定时任务
./main -mode=consumer # 仅消息消费者
./main -mode=cmd -cmd.name=example-simple -cmd.args=key1:value1 # 一次性命令# 独立工具仓 github.com/gomooth/mooth
mooth new-module order --faces user,admin,job
mooth add-face order --face consumer
mooth add-consumer order --topic order.created --engine kafka # 非 redis 引擎自动连带启用接线
mooth add-producer order --topic order.created
mooth add-job order --name order.cleanup --spec "*/10 * * * *"
mooth add-cmd order --name order:export从 clone 到第一个业务闭环的完整旅程(决策流与各步详解)见 docs/module-creation.md。
生成整棵 modules/order/ 子树并重生成 modules/modules.go 装配清单——不改任何手写文件。
模块内追加(消费者/生产者/任务/命令)按 topic/任务/命令粒度落既有模块,--engine
非 redis 时自动连带启用引擎接线(go get + engines.go 注册块 + tidy + 配置段)。
架构红线(import 白名单)由 internal/archtest 守护测试在 CI 强制。
所需 mooth 版本:本模板的模块结构版本为 TEMPLATE_LAYOUT_V6(权威源:仓根
.mooth-layout 机器可读标记,配套
mooth TEMPLATE_LAYOUT_V6)。mooth 每条生成
命令执行前自动对拍该标记——版本漂移会在第一秒硬报错并给出重装指令,无需人工
比对,也不必等守护测试红才发现;mooth doctor 可随时一键体检(版本配套 / config
完整性 / 引擎接线 / 编译)。模板结构升级时两仓同步发版(改 .mooth-layout 一行即
配套发布纪律的物化)。