protoc-gen-go-drpc: generate HTTP gateway routes from proto annotations#56
Merged
shubhamdhama merged 1 commit intoMay 14, 2026
Merged
Conversation
There was a problem hiding this comment.
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.HTTPRouteas a shared struct for generated HTTP route metadata. - Extends
protoc-gen-go-drpcto readgoogle.api.httpannotations and generateDRPC<Service>GatewayRoutesfunctions (skipping streaming RPCs / unannotated methods). - Adds
google.golang.org/genproto/googleapis/apidependency 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.
|
|
||
| // 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. |
cthumuluru-crdb
left a comment
There was a problem hiding this comment.
Can you include an example of generated code in the comment?
Author
|
@cthumuluru-crdb done |
cthumuluru-crdb
approved these changes
May 14, 2026
cthumuluru-crdb
left a comment
There was a problem hiding this comment.
LGTM! Can you also add a sample generated code as a reference before you merge these changes?
shubhamdhama
commented
May 14, 2026
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>
2e46b92 to
d1e1fa7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Read
google.api.httpannotations from proto method options and emitDRPC<Service>GatewayRoutesfunctions in the generated*_drpc.pb.gofiles. Each function returns a
[]drpc.HTTPRoutecontaining the HTTPmethod, 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.