go.mod
rpc
rpc服务api
api http调用cronjob
task任务script
脚本rmp
队列model
数据库
文件夹tree说明
xxx-service
|____go.mod
|____README.md
|____rpc
| |____xxxxx
|____api
| |____xxxxx
|model
| |____xxxxx
|cronjob
| |____xxxxx
|script
| |____xxxxx
|rmp
| |____xxxxx
- 点击菜单栏 Goland
- Preferences
- Go -> Go Modules
- 打钩✅Enable Go modules integration
- 配置GOPROXY 选择 direct保存
go mod init
- 根目录
cd api
- 创建api的模板
buybuybuyService.api
- 生成api文件夹路径
goctl api go -api buybuybuyService.api -dir . -style goZero
也可以根目录下,使用makefile命令
make goctl-api
- 根目录
cd rpc
- 生成模板
goctl rpc template -o=buybuybuyService.proto
- 编辑
buybuybuyService.proto
定义- package 规范
# 使用全小写 package buybuybuycrpc
- service 规范
service BuybuybuyRPC {}
- 生成rpc文件夹路径
goctl rpc proto -src buybuybuyService.proto -dir . -style goZero
也可以根目录下,使用makefile命令
make goctl-rpc
- 根目录
cd model
goctl model mysql datasource -url="account:password(db_ip:3306)/db_name" -table="table_name" -dir="." -style goZero
- 生成对应的table_name的数据库文件.go
- 切记代码风格
-style goZero
无论是api/rpc生成都有对应的internal文件夹
./etc/xxxService.yaml
配置数据库,redis,mq位置信息
./internal/config/config.go
配置数据库,redis,其他外部组件信息./internal/svc/serviceContext.go
配置数据库关系,外部rpc调用关系./internal/logic
编写代码逻辑
- mac的idea
- 点击右上角的add configuration打开界面
- 点击左上角"+"
- 选择go build
- package path 相对路径 eg: package path: code.wecochat.com/mesa/buybuybuy-service/api
- working directory 项目的绝对路径 eg: working directory: 绝对路径../buybuybuy-service/api
- 点击 play 或者 debug, 及运行