Skip to content

feat: add --client-only flag for goctl rpc protoc to generate only rpc client code #5665

Open

Description

@QZ-dolphin

Is your feature request related to a problem? Please describe.
I'm always frustrated when generating gRPC client code for go-zero API gateway. Currently, the goctl rpc protoc command always generates a complete RPC server skeleton, including redundant etc, internal, and service entry files, even if I only need the RPC client for API service invocation.
These extra server files are completely unnecessary for API gateway projects and require manual deletion every time, which is redundant and inefficient for cross-language gRPC invocation scenarios (e.g., calling Python gRPC services registered in etcd).

Describe the solution you'd like
I would like to add a --client-only flag for the goctl rpc protoc command.
When this flag is enabled:

  1. Only generate pb.go, grpc.pb.go and go-zero wrapped rpc client code
  2. Skip generating all server-side code, including etc, internal, service main file and server implementation code

This allows developers to generate clean client code specifically for API gateway consumption.

Describe alternatives you've considered

  1. Manually delete redundant server files after each generation (error-prone and inefficient)
  2. Use pure native protoc command without go-zero client encapsulation (lose go-zero's zrpc capability like service discovery, circuit breaker, load balancing)

No clean and official solution exists for pure client generation right now.

Additional context
In go-zero layered architecture, API services only depend on RPC clients and never host RPC server services. A dedicated client-only generation flag fits the official layered design and greatly improves development experience for microservice gateway scenarios.

Activity

  1. fzlzjerry commented on Sep 8, 2026

    @fzlzjerry

    I'd like to work on this. The current --client option controls whether the client wrapper is generated, but it does not provide a mode that skips the server skeleton.

    I'll add an opt-in --client-only mode to goctl rpc protoc, keeping the default output unchanged and avoiding server-directory creation as well as server templates. I'll cover generation inside an existing Go module, standalone output, multiple services, and imported message types, then compile the generated clients. Combining --client-only with --client=false should fail before creating output files rather than silently producing an incomplete result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions