RPC Service
High-performance gRPC microservice framework based on Protocol Buffers
jzero new your_project --frame rpc
Features
- Protocol Buffers for service interfaces
- gRPC high-performance binary protocol
- Field validation with buf.validate
- Multiple proto files support
- Middleware configuration support
- Type-safe interfaces
- Auto-generated zrpc clients
- Service mesh ready
Getting Started Guide
RPC Service Template Guide
Overview
The RPC service template provides a high-performance microservice framework based on Protocol Buffers. Define service interfaces through Proto description language with automatic code generation and type-safe communication.
Core Features
1. Proto Description Language
Define service interfaces using Protocol Buffers:
syntax = "proto3";
package user;
option go_package = "./user";
service UserService {
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
}
message CreateUserRequest {
string name = 1;
string email = 2;
}
message CreateUserResponse {
int64 id = 1;
string name = 2;
}2. Field Validation
Use buf.validate for field validation:
import "validate/validate.proto";
message CreateUserRequest {
string name = 1 [(validate.rules).string.min_len = 1];
string email = 2 [(validate.rules).string.email = true];
}3. Middleware Support
Support configuring middleware in services for authentication, logging, rate limiting, etc.
Common Commands
Add Proto Files
Add proto files in the desc/proto folder:
# Service is Test
jzero add proto testGenerate Code
# Generate service code
jzero gen
# Generate based on changed files
jzero gen --git-change
# Generate by specifying description directory or file
jzero gen --desc desc/
jzero gen --desc desc/proto/user.protoGenerate Client
# Generate zrpc client
jzero gen zrpcclientProject Structure
.
├── desc/ # Description files
│ └── proto/ # Proto description files
│ └── user.proto # User service Proto definition
├── internal/
│ ├── logic/ # Business logic
│ ├── server/ # gRPC server
│ ├── svc/ # Service context
│ └── middleware/ # Middleware
└── cmd/
└── server.go # Service entry pointDevelopment Workflow
- Add Proto File: Run
jzero add proto testto create proto file in desc/proto/ directory - Generate Code: Run
jzero gento generate code - Implement Logic: Implement business logic in
internal/logic/ - Generate Client: Run
jzero gen zrpcclientto generate client