go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

Can we support --go-json_out?

Open zxfrocky opened this issue 3 weeks ago • 1 comments

go install github.com/mitchellh/protoc-gen-go-json

goctl rpc protoc nexus_srv.proto --go_out=.. --go-grpc_out=.. --go-json_out=. --zrpc_out=./cmd/rpcserver/nexussrv/interface --style=gozero -m

报错了

unknown flag: --go-json_out

zxfrocky avatar Dec 04 '25 02:12 zxfrocky

Thanks for the feature request!

While I understand the appeal of using protoc-gen-go-json, we've decided not to add explicit support for --go-json_out in goctl at this time. Here's our reasoning:

Current approach: goctl focuses on supporting the standard protobuf code generation workflow (--go_out and --go-grpc_out) that integrates seamlessly with go-zero's built-in JSON handling through our httpx and rest packages.

Alternative solution: If you need custom protoc plugins, you can call protoc directly first for your custom outputs, then use goctl for go-zero code generation:

# First, use protoc with your custom plugins
protoc nexus_srv.proto --go_out=.. --go-grpc_out=.. --go-json_out=.

# Then use goctl for go-zero specific code
goctl rpc protoc nexus_srv.proto --go_out=.. --go-grpc_out=.. --zrpc_out=./cmd/rpcserver/nexussrv/interface --style=gozero -m

Our concern: Supporting arbitrary third-party protoc plugins would:

  • Add complexity to goctl's interface
  • Make it harder to maintain consistency across go-zero projects
  • Create potential support burden for plugin-specific issues

We prefer to keep goctl focused on the opinionated, production-tested patterns that work well with go-zero's ecosystem. The standard protobuf JSON serialization via protojson has worked reliably for projects handling tens of millions of users.

If you have specific JSON serialization requirements that can't be addressed with the current approach, we'd be interested to hear more about your use case!

kevwan avatar Dec 07 '25 03:12 kevwan