Framework Overview | go-zero Documentation (2024)


Shorten distance from demand to offline

go-zero is a web and rpc framework that integrates various engineering practices.Flexible design guarantees stability at the same end and undergoes a full operational test.

go-Zero contains very simple API definitions and generation tools goctl. Can generate Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript code based on defined api files and can be run directly.

Benefits of using go-zero

  • Easily get stability to support millions of living services
  • Intra-stage timeout control, limited flow, adaptive melting, adaptive loop and adaptive loop capability for microservice governance without configuration or extra code
  • Microservice Governance Middleware can be seamlessly integrated into other existing frameworks using
  • Useful API description, all end code generated by one click
  • Auto-Verify Client Request Parameters
  • A large number of micro-service governance and parallel development kits

Framework Overview | go-zero Documentation (1)

1. go-zero framework background

At the beginning of 18 years, we decided to migrate from a single architecture of Java+MongoDB to a microservice architecture, after careful thought and comparison, we decided to:

  • Based on Go Language
    • Efficient performance
    • Simple Syntax
    • Widespread validating engineering efficiency
    • Extreme deployment experience
    • Very low service resource cost
  • Self-research micro-service frameworks
    • Many micro-service framework self-research experience
    • A faster problem location capability is required
    • Easier add new features

2. Thinking on go-zero framework design

With regard to the design of the framework for microservices, we expect to guarantee the stability of microservices with a special focus on research and development efficiency.So at the beginning of the design, we had some guidelines as follows:

  • Stay simple, first principle
  • Flexible Design, Programming for Failure
  • Tools are larger than contracts and documents
  • High Available
  • High Conversion
  • High Scalability
  • Development friendly, encapsulated complexity
  • Only one way to bind to do one thing

In less than half a year, we have completely migrated from Java+MongoDB to Golang+MySQL , the primary microservice system, fully online at the end of August 18, and have stabilized the rapid growth of business follow-up and ensured high availability of the entire service.

3. Implementation and characteristics of the go-zero project

go-zero is an integrated web and rpc framework with various engineering practices, with the following key features:

  • Powerful tool support, minimum code writing
  • Very simple interface
  • Fully compatible net/http
  • Support Middleware for Extensions
  • High Performance
  • Programming for failure, flexible design
  • Built-in Services Discovery, Load Balancer
  • Internal limit flow, melt, download, and automatically trigger, restore automatically
  • API Parameters Auto-Validation
  • Timeout link control
  • Auto Cache Control
  • Link tracking, statistics alerts, etc.
  • High and sustained stability, which guarantees daily flow peaks during the epidemic

As shown below, we guarantee high availability of overall services at multiple levels:

Framework Overview | go-zero Documentation (2)

Don't note star : capping_hands:

4. Installation

Install under project directory:

5. Quick Start

  1. Full example please view

    Quick Build High & Microservice

    Quick Build High & Microservice - Multi-RPC

  2. Install goctl tools

    goctl read go control, don't read go C-T-L.goctl means not being controlled by code but to control it.The go does not mean golang.

    GO111MODULE=on GOPROXY=,direct go get -u

    If using version go1.16, you can install the go install command

    GOPROXY=,direct go install

    Make sure goctl is executable

  3. Quickly generate api service

    goctl api new greet
    cd greet
    go mod init
    go mod tidy
    go run greet.go -f etc/greet-api.yaml

    Default listener at 8888 port (can be modified in configuration file), can request by curl:

    curl -i http://localhost:8888/from/you

    Return to the following:

    HTTP/1.1 200 OK
    Content-Type: application/json; charset=utf-8
    Traceparent: 00-45fa9e7a7c505bad3a53a024e425ace9-eb5787234cf3e308-00
    Date: Thu, 22 Oct 2020 14:03:18 GMT
    Content-Length: 14

    Write business code:

    * api file defines the routing of the service to be exposed, reference [api norms](
    * Can pass dependencies to logic, such as mysql, redis and so on in servicecontext.go
    * Add business processing logic to the get/post/put/delete request
  4. Java, TypeScript, Dart, JavaScript code can be generated from api files

    goctl api java -api greet.api -dir greet
    goctl api dart -api greet.api -dir greet

6. Benchmark

Framework Overview | go-zero Documentation (3)

Test code is here


goctl-swaggerGenerate api document swagger
goctl-androidGenerate java (android) http client request code
goctl-go-compactMerge api with the same group in handler to a go file

8. Wechat

go-zero related articles are displayed in microservice practice public sign up and welcome snippets, and can also be used by public contact me : capping_hands:

Framework Overview | go-zero Documentation (4)

9. Wechat groups

If you do not cover any questions in the document, you are welcome to ask in the group and we will reply as soon as possible.

You can set out in the group where improvements are needed, and we will consider reasonableness and modify it as soon as possible.

If you find bugs please submit them in a timely manner issuewe will confirm and modify them as soon as possible.

Add my previous point star, a small star is the power of authors to answer the question of the volume: handshake:

Framework Overview | go-zero Documentation (5)

Framework Overview | go-zero Documentation (2024)
Top Articles
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6039

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.