tools/goctl/rpc/example/05-multiple-services/README.md
--multiple)This example demonstrates generating multiple RPC services from a single proto file.
Two proto files share the same go_package:
option go_package = "example.com/demo/pb";
shared.proto — Defines shared message types (Meta).multi.proto — Defines two services: SearchService and NotifyService.The -m (or --multiple) flag is required when a proto file contains more than one service block.
First, initialize the output directory with a go.mod:
mkdir -p output && cd output && go mod init example.com/demo && cd ..
Then generate the code with the -m flag:
goctl rpc protoc multi.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I . \
-m
Generated directory structure:
output/
├── client
│ ├── notifyservice
│ │ └── notifyservice.go
│ └── searchservice
│ └── searchservice.go
├── etc
│ └── multisvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── notifyservice
│ │ │ └── notifylogic.go
│ │ └── searchservice
│ │ └── searchlogic.go
│ ├── server
│ │ ├── notifyservice
│ │ │ └── notifyserviceserver.go
│ │ └── searchservice
│ │ └── searchserviceserver.go
│ └── svc
│ └── servicecontext.go
├── multisvc.go
└── pb
├── multi.pb.go
├── multi_grpc.pb.go
└── shared.pb.go
-m (or --multiple) flag enables multiple-service mode.client/ contains per-service subdirectories; logic/ and server/ are also grouped by service name.multisvc.go) and config.--multiple, goctl only allows one service block per proto file.config.go and servicecontext.go.