RPC Generation
RPC Generation
Section titled “RPC Generation”goctl rpc protoc reads a standard .proto file and generates a complete zrpc service alongside the Go protobuf bindings.
Prerequisites
Section titled “Prerequisites”# Install protocbrew install protobuf
# Install Go pluginsgo install google.golang.org/protobuf/cmd/protoc-gen-go@latestgo install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Verifygoctl env check --installCommand
Section titled “Command”goctl rpc protoc \ greeter.proto \ --go_out=. \ --go-grpc_out=. \ --zrpc_out=. \ -m # generate multiple servicesProto File Requirements
Section titled “Proto File Requirements”syntax = "proto3";
package greeter;option go_package = "./greeter"; // required
message SayHelloReq { string name = 1; }message SayHelloResp { string message = 1; }
service Greeter { rpc SayHello(SayHelloReq) returns(SayHelloResp);}Generated Layout
Section titled “Generated Layout”greeter/├── etc/greeter.yaml # config template├── internal/│ ├── config/config.go│ ├── logic/sayhellologic.go│ ├── server/greeterserver.go│ └── svc/servicecontext.go├── greeter/ # protobuf generated files│ ├── greeter.pb.go│ └── greeter_grpc.pb.go└── greeter.go # main entry pointClient Configuration
Section titled “Client Configuration”GreeterRpc: Etcd: Hosts: [etcd:2379] Key: greeter.rpc Timeout: 2000