Skip to content

protoc-gen-go-drpc: generate HTTP gateway routes from proto annotations#56

Merged
shubhamdhama merged 1 commit into
cockroachdb:mainfrom
shubhamdhama:auto-generate-httproute-info
May 14, 2026
Merged

protoc-gen-go-drpc: generate HTTP gateway routes from proto annotations#56
shubhamdhama merged 1 commit into
cockroachdb:mainfrom
shubhamdhama:auto-generate-httproute-info

Conversation

@shubhamdhama
Copy link
Copy Markdown

Read google.api.http annotations from proto method options and emit
DRPC<Service>GatewayRoutes functions in the generated *_drpc.pb.go
files. Each function returns a []drpc.HTTPRoute containing the HTTP
method, path, and a reference to the corresponding RPC client method.

This lets consumers (like CockroachDB's DRPC gateway) register HTTP
routes from generated data instead of maintaining manual route tables
that drift out of sync with proto definitions. Streaming RPCs and
methods without HTTP annotations are skipped.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds HTTP gateway route metadata generation to protoc-gen-go-drpc by reading google.api.http method annotations and emitting per-service DRPC<Service>GatewayRoutes helpers that return []drpc.HTTPRoute for consumers to register routes programmatically.

Changes:

  • Introduces drpc.HTTPRoute as a shared struct for generated HTTP route metadata.
  • Extends protoc-gen-go-drpc to read google.api.http annotations and generate DRPC<Service>GatewayRoutes functions (skipping streaming RPCs / unannotated methods).
  • Adds google.golang.org/genproto/googleapis/api dependency for HTTP annotations.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

File Description
go.mod Adds genproto API module dependency required to read google.api.http annotations.
go.sum Updates sums for newly added genproto modules.
drpc.go Adds exported HTTPRoute struct used by generated gateway route helpers.
cmd/protoc-gen-go-drpc/main.go Implements annotation parsing and emits DRPC<Service>GatewayRoutes with per-binding routes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drpc.go Outdated

// HTTPRoute describes an HTTP route for a DRPC gateway endpoint.
// Generated code emits functions that return slices of these, one per
// google.api.http-annotated RPC method.
Copy link
Copy Markdown

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include an example of generated code in the comment?

Comment thread cmd/protoc-gen-go-drpc/main.go
@shubhamdhama
Copy link
Copy Markdown
Author

@cthumuluru-crdb done

@cthumuluru-crdb cthumuluru-crdb self-requested a review May 14, 2026 05:04
Copy link
Copy Markdown

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Can you also add a sample generated code as a reference before you merge these changes?

Comment thread cmd/protoc-gen-go-drpc/main.go
Read `google.api.http` annotations from proto method options and emit
`DRPC<Service>GatewayRoutes` functions in the generated `*_drpc.pb.go`
files. Each function returns a `[]drpc.HTTPRoute` containing the HTTP
method, path, and a reference to the corresponding RPC client method.

This lets consumers (like CockroachDB's DRPC gateway) register HTTP
routes from generated data instead of maintaining manual route tables
that drift out of sync with proto definitions. Streaming RPCs and
methods without HTTP annotations are skipped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shubhamdhama shubhamdhama force-pushed the auto-generate-httproute-info branch from 2e46b92 to d1e1fa7 Compare May 14, 2026 06:20
@shubhamdhama shubhamdhama merged commit a5d8e95 into cockroachdb:main May 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants