/go-zero

A cloud-native Go microservices framework with cli tool for productivity.

Primary LanguageGoMIT LicenseMIT

Fork之后改了什么?

  1. goctl api go 支持time.Time字段
  2. 支持action路由生成
  3. config改为viper,字段默认值,字段验证有所调整
  4. logx日志库有所调整,改为zap

🤷‍ What is go-zero?

English | 简体中文

go-zero - A web & rpc framework written in Go. | Product Hunt

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.

Installation

Run the following command under your project:

go get -u github.com/zeromicro/go-zero

Quick Start

  1. install goctl

    goctlcan be read as go control. goctl means not to be controlled by code, instead, we control it. The inside go is not golang. 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.

  2. 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
  3. generate the go server-side code

    goctl api go -api greet.api -dir greet