- goctl api go 支持time.Time字段
- 支持action路由生成
- config改为viper,字段默认值,字段验证有所调整
- logx日志库有所调整,改为zap
English | 简体中文
go-zero (listed in CNCF Landscape: https://landscape.cncf.io/?selected=go-zero) is a web and rpc framework with lots of builtin engineering practices. It’s born to ensure the stability of the busy services with resilience design and has been serving sites with tens of millions of users for years.
go-zero contains simple API description syntax and code generation tool called goctl
. You can generate Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript from .api files with goctl
.
Run the following command under your project:
go get -u github.com/zeromicro/go-zero
-
install goctl
goctl
can be read asgo control
.goctl
means not to be controlled by code, instead, we control it. The insidego
is notgolang
. At the very beginning, I was expecting it to help us improve productivity, and make our lives easier.git clone https://github.com/zhouchang2017/go-zero.git cd go-zero/tools/goctl go mod tidy go install
make sure goctl is executable.
-
create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported.
type ( Request { Name string `path:"name,options=you|me"` // parameters are auto validated } Response { Message string `json:"message"` } ) @server( action: appapiv1 middleware: AccessLoggerMiddleware,AuthMiddleware ) service greet-api { @handler GreetHandler get /GreetHandler(Request) returns (Response) }
the .api files also can be generated by goctl, like below:
goctl api -o greet.api
-
generate the go server-side code
goctl api go -api greet.api -dir greet