基础命令
- go mod init xxx 初始化xxx
- go mod tidy 添加依赖
nest与go-zero对比 Go-Zero NestJS
Handler ≈ Controller 的路由部分 Logic ≈ Service + Controller 的业务部分 ServiceContext ≈ 依赖注入容器 (Module) model ≈ Repository/Entity
结果-错误模式: 如果是正确的正常返回,如有错误的就抛出错误,否则返回nil
go
func (l *HelloLogic) Hello(req *types.Testequest) (resp *types.TestResponse, err error) {
// todo: add your logic here and delete this line
resp = &types.TestResponse{
Reply: "Hello, " + req.Message,
}
return resp, nil
}
数据库连接:
sh
goctl model mysql datasource -url="user:password@tcp(127.0.0.1:3306)/database" -table="user" -dir="./model" -cache=true