A lightweight gRPC microservice framework for Go, stripped from go-zero.
Focuses on one thing: building gRPC services, with no extra baggage.
- gRPC server & client with clean lifecycle management
- Built-in interceptors: tracing (OpenTelemetry), Prometheus metrics, timeout, panic recovery
- Structured logging (
logx) - YAML/JSON/TOML config loading (
conf) - Graceful shutdown with signal handling
- Health check & DevServer (pprof + metrics endpoint)
- CLI tool for project scaffolding and code generation
REST framework, MySQL/PostgreSQL/MongoDB/Redis, message queues, etcd/K8s service discovery, P2C load balancing, circuit breaker, load shedding, HTTP gateway, MCP, JWT auth, goctl.
go install github.com/qwqzy/grpcx/cmd/grpcx@latestgrpcx new myservice
cd myservice
go mod tidy
go run main.goThis generates a complete project with a Ping RPC example:
myservice/
├── etc/myservice.yaml
├── internal/
│ ├── config/config.go
│ ├── logic/ping_logic.go
│ ├── server/myservice_server.go
│ └── svc/servicecontext.go
├── myservice/
│ ├── myservice.proto
│ ├── myservice.pb.go
│ └── myservice_grpc.pb.go
├── go.mod
└── main.go
grpcx gen path/to/service.protogrpcx doctorVerifies protoc, protoc-gen-go, and protoc-gen-go-grpc are installed and in PATH.
Name: myservice.rpc
ListenOn: 0.0.0.0:8080
Mode: dev # dev | test | pro
Timeout: 2000 # ms, 0 = no timeout
Health: true
Log:
Mode: console
Telemetry:
Name: myservice
Endpoint: localhost:4317
Sampler: 1.0Endpoints:
- localhost:8080
Timeout: 2000
NonBlock: truegrpcx/
├── config.go # RpcServerConf / RpcClientConf
├── server.go # gRPC server
├── client.go # gRPC client
├── logger.go # gRPC log adapter
├── serverinterceptors/ # Server interceptors: trace, recover, prometheus, timeout
├── clientinterceptors/ # Client interceptors: trace, prometheus, timeout
├── resolver/ # Direct endpoint resolver
├── cmd/grpcx/ # CLI tool (new, gen, doctor, version)
└── core/
├── conf/ # Config loading (YAML/JSON/TOML)
├── logx/ # Structured logging
├── logc/ # Context-aware logging
├── trace/ # OpenTelemetry tracing
├── metric/ # Prometheus metric helpers
├── proc/ # Process lifecycle & graceful shutdown
├── prometheus/ # Prometheus agent
├── devserver/ # Dev HTTP server (health + metrics + pprof)
├── health/ # Health check probe
├── encoding/ # YAML/TOML/JSON5 encoding
├── mapping/ # Struct tag mapping (config engine)
└── ... # Other utility packages
MIT
一个轻量级的 Go gRPC 微服务框架,从 go-zero 精简而来。
只做一件事:构建 gRPC 服务,没有多余的东西。
- gRPC 服务端和客户端,完整的生命周期管理
- 内置拦截器:链路追踪(OpenTelemetry)、Prometheus 指标、超时控制、panic 恢复
- 结构化日志(
logx) - YAML/JSON/TOML 配置加载(
conf) - 信号监听 + 优雅停机
- 健康检查 & DevServer(pprof + metrics 端点)
- CLI 工具:项目脚手架 & 代码生成
REST 框架、MySQL/PostgreSQL/MongoDB/Redis、消息队列、etcd/K8s 服务发现、P2C 负载均衡、熔断器、自适应降载、HTTP 网关、MCP、JWT 认证、goctl。
go install github.com/qwqzy/grpcx/cmd/grpcx@latestgrpcx new myservice
cd myservice
go mod tidy
go run main.go自动生成包含 Ping RPC 示例的完整项目:
myservice/
├── etc/myservice.yaml
├── internal/
│ ├── config/config.go
│ ├── logic/ping_logic.go
│ ├── server/myservice_server.go
│ └── svc/servicecontext.go
├── myservice/
│ ├── myservice.proto
│ ├── myservice.pb.go
│ └── myservice_grpc.pb.go
├── go.mod
└── main.go
grpcx gen path/to/service.protogrpcx doctor检查 protoc、protoc-gen-go、protoc-gen-go-grpc 是否已安装并在 PATH 中。
Name: myservice.rpc
ListenOn: 0.0.0.0:8080
Mode: dev # dev | test | pro
Timeout: 2000 # 毫秒,0 = 不超时
Health: true
Log:
Mode: console
Telemetry:
Name: myservice
Endpoint: localhost:4317
Sampler: 1.0Endpoints:
- localhost:8080
Timeout: 2000
NonBlock: truegrpcx/
├── config.go # RpcServerConf / RpcClientConf
├── server.go # gRPC 服务端
├── client.go # gRPC 客户端
├── logger.go # gRPC 日志适配
├── serverinterceptors/ # 服务端拦截器:trace, recover, prometheus, timeout
├── clientinterceptors/ # 客户端拦截器:trace, prometheus, timeout
├── resolver/ # 直连地址解析器
├── cmd/grpcx/ # CLI 工具(new, gen, doctor, version)
└── core/
├── conf/ # 配置加载(YAML/JSON/TOML)
├── logx/ # 结构化日志
├── logc/ # 带 context 的日志
├── trace/ # OpenTelemetry 链路追踪
├── metric/ # Prometheus 指标封装
├── proc/ # 进程生命周期 & 优雅停机
├── prometheus/ # Prometheus 代理
├── devserver/ # 开发 HTTP 服务(健康检查 + 指标 + pprof)
├── health/ # 健康检查探针
├── encoding/ # YAML/TOML/JSON5 编码
├── mapping/ # 结构体标签映射(配置引擎)
└── ... # 其他工具包
MIT