Go Version License Build Status
heytom-cli 是一个命令行工具集,用于简化 heytom 框架体系的开发工作流程。
- 🚀 Proto 管理: 初始化、生成、检查和导入 Protocol Buffer 文件
- 📦 项目脚手架: 快速创建 Go 和 C# 微服务项目
- 🔄 数据库迁移: 管理数据库 schema 的版本变更
- ✅ 代码规范检查: 使用 Buf 进行 Proto 文件的 lint 和 breaking change 检测
- 🛠️ 依赖检查: 自动检测和提示必需的工具依赖
git clone https://github.com/heytom/heytom-cli.git
cd heytom-cli
go build -o heytom-cli ./cmd/heytom-cligo install github.com/heytom/heytom-cli/cmd/heytom-cli@latest
- Go 1.21+
- Buf CLI (用于 Proto 文件管理)
检查依赖:
heytom-cli check-deps
创建 Go 服务:
heytom-cli new service my-service --lang go
cd my-service创建 C# 服务:
heytom-cli new service my-service --lang csharp
cd my-service初始化 Proto 项目:
heytom-cli proto init my-service --lang go
创建新的 Proto 文件:
heytom-cli new proto user --version v1
生成代码:
heytom-cli proto gen
检查代码规范:
heytom-cli proto lint
检查破坏性变更:
heytom-cli proto breaking --against main
创建迁移文件:
heytom-cli new migration create_users_table
应用迁移:
heytom-cli migrate up --dsn "postgres://user:pass@localhost/db"回滚迁移:
heytom-cli migrate down --dsn "postgres://user:pass@localhost/db"heytom-cli proto init [service-name]- 初始化 Proto 项目结构heytom-cli proto gen- 从 Proto 文件生成代码heytom-cli proto lint- 检查 Proto 文件规范heytom-cli proto breaking- 检测破坏性变更heytom-cli proto import [source-path]- 导入其他服务的 Proto 文件
heytom-cli new service [name]- 创建新的微服务项目heytom-cli new proto [service-name]- 创建新的 Proto 文件heytom-cli new migration [name]- 创建数据库迁移文件
heytom-cli migrate up- 应用待执行的迁移heytom-cli migrate down- 回滚迁移
heytom-cli version- 显示版本信息heytom-cli check-deps- 检查依赖工具heytom-cli help- 显示帮助信息
使用 heytom-cli 创建的服务遵循以下结构:
my-service/
├── api/ # Proto 文件
│ └── my-service/
│ └── v1/
│ └── my-service.proto
├── cmd/
│ └── my-service/
│ └── main.go # 服务入口
├── internal/
│ ├── service/ # 业务逻辑
│ └── handler/ # gRPC 处理器
├── gen/ # 生成的代码
├── migrations/ # 数据库迁移
├── buf.yaml # Buf 配置
├── buf.gen.yaml # 代码生成配置
└── go.mod
my-service/
├── api/ # Proto 文件
├── src/
│ ├── Program.cs # 服务入口
│ └── my-service.csproj
├── gen/ # 生成的代码
├── migrations/ # 数据库迁移
├── buf.yaml
└── buf.gen.yaml
go build -o heytom-cli ./cmd/heytom-cli
go test ./...MIT License
欢迎提交 Issue 和 Pull Request!