feat: add protoc-gen-connect-go-service-struct plugin#4
Conversation
|
Warning Rate limit exceeded@yordis has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 29 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
WalkthroughIntroduces a new protoc plugin (protoc-gen-connect-go-servicestruct) that generates Go service structs and handler function types for Connect RPC services, adds its README, comprehensive tests, adjusts module dependencies, and updates .gitignore to ignore the plugin’s generated build artifact. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant protoc as protoc/buf
participant plugin as protoc-gen-connect-go-servicestruct
participant protogen as protogen API
participant fs as File System
protoc->>plugin: CodeGeneratorRequest (files, params)
plugin->>protogen: Parse request, analyze services
loop per Go import path group
plugin->>plugin: Generate service structs & handler types
plugin->>fs: Emit *.servicestruct.connect.go (in-memory response)
end
plugin-->>protoc: CodeGeneratorResponse (generated files)
sequenceDiagram
autonumber
participant App as Application Server
participant S as <ServiceName>Struct
participant H as <MethodName>Func (handler)
participant Conn as connect runtime
App->>S: Register S with Connect mux
Conn->>S: Invoke RPC (unary/streaming)
alt Unary
S->>H: ctx, *connect.Request[In]
H-->>S: *connect.Response[Out], error
else Client stream
S->>H: ctx, *connect.ClientStream[In]
H-->>S: *connect.Response[Out], error
else Server stream
S->>H: ctx, *connect.Request[In], *connect.ServerStream[Out]
H-->>S: error
else Bidi stream
S->>H: ctx, *connect.BidiStream[In,Out]
H-->>S: error
end
S-->>Conn: Forward result/error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a469054 to
d9a36da
Compare
7523022 to
5271042
Compare
5271042 to
3a6b8d1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
go.mod (1)
3-3: Invalidgodirective: use major.minor only
go 1.24.2is not valid ingo.mod. The directive must bego 1.24(patch versions are not allowed).Apply this diff:
-go 1.24.2 +go 1.24If you need to pin a specific toolchain, add a separate toolchain directive:
toolchain go1.24.2
🧹 Nitpick comments (5)
cmd/protoc-gen-connect-go-servicestruct/README.md (1)
1-110: Solid README; add prerequisites section for clarityConsider a short “Requirements” block listing protoc,
protoc-gen-go, andprotoc-gen-connect-gowith minimum versions, plus the Go version (e.g., Go 1.24+). Helps users avoid setup surprises.cmd/protoc-gen-connect-go-servicestruct/main_test.go (1)
308-323: Minor: exitCode checks are redundant afterrequire.NoError
require.NoError(cmd.Run())already guaranteesexitCode == 0. You can drop the extra equality assert, or switch to checking exitCode and useassert.NoErroron run to keep both signals.cmd/protoc-gen-connect-go-servicestruct/main.go (3)
55-61: Decouple--versionfrom connect library versionPrinting
connect.Versionreports the Connect library version, not this plugin’s. Expose a plugin version variable and set it via-ldflagsduring release builds; drop the unusedconnectimport afterward.Apply this diff to use a pluggable version:
func main() { - if len(os.Args) == 2 && os.Args[1] == "--version" { - if _, err := fmt.Fprintln(os.Stdout, connect.Version); err != nil { + if len(os.Args) == 2 && os.Args[1] == "--version" { + if _, err := fmt.Fprintln(os.Stdout, version); err != nil { os.Exit(1) } os.Exit(0) }Add this right after the
constblock:+// version is set at build time: -ldflags "-X main.version=$(git describe --tags --always --dirty)" +var version = "dev"And remove the now‑unused import:
-import ( - "bytes" - "fmt" - "os" - "strings" - "unicode/utf8" - - connect "connectrpc.com/connect" +import ( + "bytes" + "fmt" + "os" + "strings" + "unicode/utf8"
80-92: Stabilize output ordering for deterministic buildsMap iteration over
packageGroupsis random; consider sorting groups and files to reduce churn in generated diffs and make tests more robust.Example patch (also add
sortto imports):import ( "bytes" "fmt" "os" "strings" "unicode/utf8" + "sort" @@ - for _, files := range packageGroups { - generatePackage(plugin, files) - } + // stable order of packages + pkgKeys := make([]string, 0, len(packageGroups)) + for k := range packageGroups { + pkgKeys = append(pkgKeys, k) + } + sort.Strings(pkgKeys) + for _, k := range pkgKeys { + files := packageGroups[k] + sort.Slice(files, func(i, j int) bool { return files[i].Desc.Path() < files[j].Desc.Path() }) + generatePackage(plugin, files) + }
179-191: Optional: guard nil handlers to improve UXCalling a nil
*Funcfield will panic at runtime. Consider defaulting to a stub that returns an unimplemented error, or check for nil and return a clear error.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (5)
.gitignore(1 hunks)cmd/protoc-gen-connect-go-servicestruct/README.md(1 hunks)cmd/protoc-gen-connect-go-servicestruct/main.go(1 hunks)cmd/protoc-gen-connect-go-servicestruct/main_test.go(1 hunks)go.mod(1 hunks)
🔇 Additional comments (2)
.gitignore (1)
33-35: Ignore rule for plugin binary looks goodCovers both root and nested outputs when running
go buildfrom different working dirs.cmd/protoc-gen-connect-go-servicestruct/main_test.go (1)
25-37: Nice parallelized test scaffoldingGood use of table-ish subtests and compiler version metadata to mimic protoc. Assertions read cleanly.
69cab85 to
1a712f4
Compare
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1a712f4 to
30b6c46
Compare
No description provided.