tools/goctl/rpc/example/02-import-sibling/README.md
This example demonstrates importing a proto file from the same directory.
Two proto files in the same directory share the same go_package:
types.proto — Defines shared message types (User).user.proto — Defines the RPC service, importing types.proto.Both files use the same go_package with a full module path:
option go_package = "example.com/demo/pb";
user.proto imports types.proto via:
import "types.proto";
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:
goctl rpc protoc user.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 .
Generated directory structure:
output/
├── etc
│ └── usersvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── createuserlogic.go
│ │ └── getuserlogic.go
│ ├── server
│ │ └── userserviceserver.go
│ └── svc
│ └── servicecontext.go
├── pb
│ ├── types.pb.go
│ ├── user.pb.go
│ └── user_grpc.pb.go
├── userservice
│ └── userservice.go
└── usersvc.go
user.proto and types.proto) share the same go_package = "example.com/demo/pb", compiled into a single Go package.user.proto imports types.proto via import "types.proto".go_package, they compile into a single Go package.service definitions needs to be passed to goctl rpc protoc.