mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-06-22 09:51:56 +08:00
Co-authored-by: kevin <wanjunfeng@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2.2 KiB
2.2 KiB
RPC Examples
This directory contains complete examples for all goctl rpc code generation scenarios.
Each example includes:
.protosource filesREADME.md(English),README-cn.md(中文), andREADME-ko.md(한국어) documentation
Examples
| # | Directory | Scenario | Key Flags |
|---|---|---|---|
| 01 | 01-basic | Basic single service, no imports | — |
| 02 | 02-import-sibling | Import sibling proto file | --proto_path=. |
| 03 | 03-import-subdir | Import proto from subdirectory | --proto_path=. |
| 04 | 04-transitive-import | Transitive imports (A → B → C) | --proto_path=. |
| 05 | 05-multiple-services | Multiple services in one proto | --multiple |
| 06 | 06-wellknown-types | Google well-known types in messages | — |
| 07 | 07-external-proto-same-pkg | External proto, same go_package |
-I ./ext_protos |
| 08 | 08-external-proto-diff-pkg | External proto, different go_package |
-I ./ext_protos |
| 09 | 09-google-types-as-rpc | Google well-known types as RPC parameters | — |
| 10 | 10-streaming | Server/client/bidirectional streaming | — |
Prerequisites
- Go 1.22+
- protoc (Protocol Buffers compiler)
- protoc-gen-go and protoc-gen-go-grpc
- goctl
Quick Start
# Install protoc plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Try the basic example
cd 01-basic
mkdir -p output && cd output && go mod init example.com/demo && cd ..
goctl rpc protoc greeter.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 .