go-zero Documentation

repository·main·Indexed 20 days ago

https://github.com/zeromicro/zero-doc

A high-performance web and RPC framework for Go designed for large-scale microservices. It features built-in resilience patterns such as circuit breaking, rate limiting, adaptive load shedding, and cascading timeout control. The framework includes the goctl tool for generating Go, Java, TypeScript, Dart, and JavaScript code from API definitions, and provides built-in support for distributed tracing, Prometheus monitoring, and JWT authentication.

Tokens
223.3K
Snippets
639
Records
941
Agent score
67%

What's inside go-zero

  1. What is goctl and its core functions

    main

    goctl is a code generation tool for the go-zero microservices framework. It is designed to increase development efficiency by automating boilerplate code. Its primary functions include:

    • API service generation: Automating the creation of API services.
    • RPC service generation: Automating the creation of RPC services.
    • Model code generation: Generating data access layer (model) code.
    • Template management: Managing custom templates for code generation.
  2. Overview of the go-zero development workflow

    main

    The go-zero project development guide covers the entire lifecycle from environment preparation to service deployment. The workflow is structured into several key phases:

    1. Environment Preparation: Setting up Go, Go modules, goctl (the go-zero command-line tool), and Protocol Buffers (protoc & protoc-gen-go).
    2. Development Standards: Following specific naming conventions (for code and routes) and coding specifications.
    3. Development Process: Understanding the core development flow and configuration for both API and RPC services.
    4. Business Logic Implementation: Managing directory structures, generating models, writing .api files, implementing business logic, handling JWT authentication, using middleware, and performing RPC calls and error handling.
    5. Operations & Deployment: Implementing CI/CD, service deployment, log collection, distributed tracing, and service monitoring.
  3. What is go-zero and its core capabilities

    main

    go-zero is a web and RPC framework designed to integrate various engineering practices. It is built to guarantee the stability of large concurrent servers through flexible design and has been tested in production environments.

    A key component of the ecosystem is goctl, a minimalist API definition and generation tool. goctl allows you to create versatile API definition files and, with a single command, generate ready-to-run code for multiple languages and platforms, including:

    • Go
    • iOS
    • Android
    • Kotlin
    • Dart
    • TypeScript
    • JavaScript
  4. Overview of the goctl api command

    main
    The goctl api module is a core component of goctl designed to automate the creation of API services from .api files. It eliminates the manual overhead of creating directory structures, defining structs, setting up routes, and adding logic files. Instead of spending minutes on boilerplate, goctl api can generate a complete, runnable API service skeleton in seconds.
  5. Overview of go-zero features

    main

    go-zero is a web and RPC framework designed to integrate various engineering practices with a focus on high availability and minimal boilerplate. Key capabilities include:

    • Developer Productivity: Powerful tool support to minimize manual code writing and a minimalist interface.
    • Compatibility: Fully compatible with Go's standard net/http package.
    • Extensibility: Supports middleware for easy expansion of functionality.
    • Resilience & Stability:
      • Built-in service discovery and load balancing.
      • Built-in traffic management: current limiting, fusing (circuit breaking), load reduction, automatic triggering, and automatic recovery.
      • Timeout cascade control.
      • Automatic cache control.
    • Observability: Link tracking and statistical alarming.
    • Reliability: API parameter automatic verification and high concurrency support designed to handle traffic peaks stably.
  6. What is go-zero

    main

    go-zero is a web and RPC framework designed for high-stability, heavy-workload services. It features resilience designs such as chained timeout control, concurrency control, rate limiting, adaptive circuit breakers, and adaptive load shedding.

    Key capabilities include:

    • Simple API description syntax using .api files.
    • Code generation via the goctl tool for multiple languages (Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript).
    • Automatic request parameter validation.
    • Built-in microservice management, service discovery, and load balancing.
    • Full compatibility with net/http.
  7. Overview of the go-zero development lifecycle

    main

    The go-zero development process follows a structured lifecycle from environment preparation to service deployment. To build and deploy services with go-zero, you will need to navigate through several key stages:

    1. Environment Preparation: Installing Golang, configuring Go modules, installing goctl, and setting up protoc with protoc-gen-go.
    2. Development Standards: Following specific naming rules (for code and routes), coding specifications, and development flows.
    3. Configuration: Setting up both API and RPC configurations.
    4. Business Development: Designing directory structures, generating models, implementing API and RPC logic, handling JWT, using middleware, and managing error handling.
    5. Operations: Implementing CI/CD, service deployment, log collection, tracing, and monitoring.
  8. What is goctl

    main

    goctl is a code generation tool for the go-zero microservice framework designed to improve development efficiency. It automates the creation of boilerplate code, allowing developers to focus on business logic.

    Key capabilities include:

    • api service generation: Creating API service structures.
    • rpc service generation: Creating RPC service structures.
    • model code generation: Generating data model code.
    • template management: Managing code templates.
  9. Overview of go-zero framework

    main

    go-zero is a web and RPC framework that integrates various engineering practices to ensure stability for high-concurrency services. It is designed with elasticity to handle massive traffic and includes built-in microservice governance capabilities without requiring extra configuration or code.

    Key Features:

    • Built-in Governance: Cascading timeout control, rate limiting, adaptive circuit breaking, and adaptive load shedding.
    • Code Generation: Uses the goctl tool to generate code for Go, iOS, Android, Kotlin, Dart, TypeScript, and JavaScript from minimal API definitions.
    • Automatic Validation: Automatically validates client request parameters.
    • Extensibility: Fully compatible with net/http and supports middleware for seamless integration into existing frameworks.
    • Observability: Built-in support for distributed tracing, statistics, and alerting.
  10. What is zRPC?

    main

    zRPC is a general-purpose RPC framework designed for high-concurrency production environments (tested with tens of millions of daily active users). It is built on top of gRPC and provides a complete set of built-in microservice governance capabilities.

    Key characteristics include:

    • Generality: Uses gRPC to support cross-language calls.
    • High Performance: Leverages the HTTP2 protocol and Protobuf serialization.
    • Extensibility: Allows users to extend functionality via custom interceptors.
    • Full Feature Set: Includes built-in service governance (authentication, logging, monitoring, statistics, tracing, timeout control, automatic circuit breaking, and automatic load shedding) as well as service registration, discovery, and load balancing without requiring manual configuration.
    • Simplicity: Can be initialized with a few lines of code and integrates with the goctl tool for automated code generation, allowing developers to focus solely on business logic.
  11. Explore the go-zero ecosystem

    main

    The go-zero ecosystem provides various tools and extensions to enhance development productivity. Key components include:

    • Tool Center: Contains specialized development tools, including IDE plugins for IntelliJ and VS Code.
    • Distributed Transaction Support: Tools and patterns for managing transactions across distributed services.
    • Plugin Center: A collection of plugins to extend go-zero functionality.