Skip to content
QwQzyPublic

About

A lightweight gRPC framework for Go, stripped from go-zero. Focuses on gRPC server/client with built-in tracing, metrics, and a simple CLI for project scaffolding.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

grpcx

A lightweight gRPC microservice framework for Go, stripped from go-zero.

Focuses on one thing: building gRPC services, with no extra baggage.

Features

  • 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

What's removed (compared to go-zero)

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.

Quick Start

Install CLI

go install github.com/qwqzy/grpcx/cmd/grpcx@latest

Create a new project

grpcx new myservice
cd myservice
go mod tidy
go run main.go

This 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

Generate from existing proto

grpcx gen path/to/service.proto

Check environment

grpcx doctor

Verifies protoc, protoc-gen-go, and protoc-gen-go-grpc are installed and in PATH.

Server Config

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.0

Client Config

Endpoints:
  - localhost:8080
Timeout: 2000
NonBlock: true

Architecture

grpcx/
├── 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

License

MIT


grpcx

一个轻量级的 Go gRPC 微服务框架,从 go-zero 精简而来。

只做一件事:构建 gRPC 服务,没有多余的东西。

特性

  • gRPC 服务端和客户端,完整的生命周期管理
  • 内置拦截器:链路追踪(OpenTelemetry)、Prometheus 指标、超时控制、panic 恢复
  • 结构化日志(logx)
  • YAML/JSON/TOML 配置加载(conf)
  • 信号监听 + 优雅停机
  • 健康检查 & DevServer(pprof + metrics 端点)
  • CLI 工具:项目脚手架 & 代码生成

相比 go-zero 删掉了什么

REST 框架、MySQL/PostgreSQL/MongoDB/Redis、消息队列、etcd/K8s 服务发现、P2C 负载均衡、熔断器、自适应降载、HTTP 网关、MCP、JWT 认证、goctl。

快速开始

安装 CLI

go install github.com/qwqzy/grpcx/cmd/grpcx@latest

创建新项目

grpcx 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

从已有 proto 生成

grpcx gen path/to/service.proto

检查环境

grpcx 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.0

客户端配置

Endpoints:
  - localhost:8080
Timeout: 2000
NonBlock: true

项目结构

grpcx/
├── 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

About

A lightweight gRPC framework for Go, stripped from go-zero. Focuses on gRPC server/client with built-in tracing, metrics, and a simple CLI for project scaffolding.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages