@@ -53,7 +53,7 @@ Goctl Rpc是`goctl`脚手架下的一个rpc服务代码生成模块,支持prot
5353``` Bash
5454$ goctl rpc template -o=user.proto
5555```
56-
56+
5757``` proto
5858syntax = "proto3";
5959
@@ -72,7 +72,7 @@ service User {
7272 rpc Ping(Request) returns(Response);
7373}
7474```
75-
75+
7676
7777* 生成rpc服务代码
7878
@@ -96,35 +96,60 @@ Examples:
9696goctl rpc protoc xx.proto --go_out=./pb --go-grpc_out=./pb --zrpc_out=.
9797
9898Flags:
99- --branch string The branch of the remote repo, it does work with --remote
100- -h, --help help for protoc
101- --home string The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
102- -m, --multiple Generated in multiple rpc service mode
103- --remote string The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
104- The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
105- --style string The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md] (default " gozero" )
106- -v, --verbose Enable log output
107- --zrpc_out string The zrpc output directory
99+ --branch string The branch of the remote repo, it does work with --remote
100+ -h, --help help for protoc
101+ --home string The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
102+ -m, --multiple Generated in multiple rpc service mode
103+ --name-from-filename Use proto filename instead of package name for service naming (legacy behavior)
104+ --remote string The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
105+ The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
106+ --style string The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md] (default " gozero" )
107+ -v, --verbose Enable log output
108+ --zrpc_out string The zrpc output directory
108109` ` `
109110
110111# ## 参数说明
111112
112113* --branch 指定远程仓库模板分支
113114* --home 指定goctl模板根目录
114115* -m, --multiple 指定生成多个rpc服务模式, 默认为 false, 如果为 false, 则只支持生成一个rpc service, 如果为 true, 则支持生成多个 rpc service,且多个 rpc service 会分组。
116+ * --name-from-filename 使用proto文件名而非package名称来命名服务(旧版行为)。默认使用package名称,这样可以支持多个proto文件共享同一个package。
115117* --style 指定文件输出格式
116118* -v, --verbose 显示日志
117119* --zrpc_out 指定zrpc输出目录
118120
119121> # # --multiple
120122> 是否开启多个 rpc service 生成,如果开启,则满足一下新特性
121- > 1. 支持 1 到多个 rpc service
123+ > 1. 支持 1 到多个 rpc service
122124> 2. 生成 rpc 服务会按照服务名称分组(尽管只有一个 rpc service)
123125> 3. rpc client 的文件目录变更为固定名称 ` client`
124- >
126+ >
125127> 如果不开启,则和旧版本 rpc 生成逻辑一样(兼容)
126128> 1. 有且只能有一个 rpc service
127129
130+ > # # Service Naming (Multi-Proto File Support)
131+ >
132+ > By default, the service name is derived from the **proto package name** (e.g., ` package user; ` → service name ` user` ).
133+ > This enables splitting a large proto file into multiple smaller files that share the same package name,
134+ > which is particularly useful for AI-assisted development where smaller files are easier to process.
135+ >
136+ > ** Example: Multiple proto files with same package**
137+ > ` ` `
138+ > protos/
139+ > ├── user_base.proto # package user;
140+ > ├── user_auth.proto # package user;
141+ > └── user_profile.proto # package user;
142+ > ` ` `
143+ > All three files will generate into a single ` user` service.
144+ >
145+ > ** Legacy behavior (--name-from-filename)**
146+ >
147+ > If you need the old behavior where service name is derived from the proto filename,
148+ > use the ` --name-from-filename` flag:
149+ > ` ` ` bash
150+ > goctl rpc protoc user.proto --go_out=./pb --go-grpc_out=./pb --zrpc_out=. --name-from-filename
151+ > ` ` `
152+
128153
129154# # rpc 服务生成 example
130155详情见 [example/rpc](https://github.com/zeromicro/go-zero/tree/master/tools/goctl/example)
0 commit comments