Skip to content

Fix naming conventions for generated gRPC templates - #81

Open
thzgajendra wants to merge 4 commits into
gofr-dev:mainfrom
thzgajendra:fix/grpc-template-naming
Open

Fix naming conventions for generated gRPC templates#81
thzgajendra wants to merge 4 commits into
gofr-dev:mainfrom
thzgajendra:fix/grpc-template-naming

Conversation

@thzgajendra

@thzgajendra thzgajendra commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Objective

Resolves #40 — the generated GoFr gRPC wrapper names the CLI's own service types with a Server suffix; rename them to Service.

// before
server.RegisterHelloServerWithGofr(app, server.NewHelloGoFrServer())
// after
server.RegisterHelloServiceWithGofr(app, server.NewHelloGoFrService())

What changed

Renamed the CLI-owned identifiers in wrap/template.go from ServerService:

Before After
{{.Service}}GoFrServer {{.Service}}GoFrService
{{.Service}}ServerWithGofr {{.Service}}ServiceWithGofr
{{.Service}}ServerWrapper {{.Service}}ServiceWrapper
Register{{.Service}}ServerWithGofr Register{{.Service}}ServiceWithGofr

Left as Server (protoc-gen-go-grpc contract symbols the generated code references): embedded {{.Service}}Server, mustEmbedUnimplemented{{.Service}}Server(), Register{{.Service}}Server(...), {{.Service}}_{{.Name}}Server streams, {{.Service}}Client/New{{.Service}}Client(...), the generic helper registerServerWithGofr, and grpc.ServerStream. The client template needed no change.

Tests

Adds wrap/template_test.go (first coverage for the package) asserting the CLI-owned types are service-named and the old names are gone, while every protoc contract symbol is preserved, and the client surface is unaffected.

Test plan

  • go test ./... — all pass, incl. the new wrap naming tests.
  • gofmt / go vet ./... clean.

Scope note

This PR is now naming-only. Two unrelated code-generation bugs I'd originally bundled here were split out so each fix is independently mergeable:

The generated GoFr gRPC wrapper used a "Server" suffix for the CLI's own
service types, e.g. RegisterHelloServerWithGofr / NewHelloGoFrServer. These
represent a service, not a server, and clashed conceptually with the
protoc-generated *Server symbols. Rename the CLI-owned identifiers to use
"Service":

- {{.Service}}GoFrServer        -> {{.Service}}GoFrService
- {{.Service}}ServerWithGofr     -> {{.Service}}ServiceWithGofr
- {{.Service}}ServerWrapper      -> {{.Service}}ServiceWrapper
- Register{{.Service}}ServerWithGofr -> Register{{.Service}}ServiceWithGofr

protoc-gen-go-grpc contract symbols are intentionally left as-is
(embedded {{.Service}}Server, mustEmbedUnimplemented{{.Service}}Server,
Register{{.Service}}Server, {{.Service}}_{{.Name}}Server streams,
{{.Service}}Client) since the generated code must reference them.

Resolves gofr-dev#40
Cover the generated GoFr gRPC wrapper/server/client naming so gofr-dev#40 cannot
regress: assert the CLI-owned types are service-named
(RegisterHelloServiceWithGofr, HelloGoFrService, HelloServiceWithGofr,
HelloServiceWrapper) while the protoc-gen-go-grpc contract symbols the code
references are left unchanged (mustEmbedUnimplementedHelloServer,
RegisterHelloServer, Hello_<Method>Server streams). This is the first test
coverage for the wrap package.
…y imports)

Found while running the generated gRPC server end-to-end. Two pre-existing
bugs made the generated server package fail to compile:

1. The request-wrapper template printed the whole ServiceRequest struct via
   {{ $request }}, emitting `type {HelloRequest HelloRequest}Wrapper struct`
   instead of `type HelloRequestWrapper struct`. Use {{ $request.Request }}.

2. The server wrapper imported "time" and the gofr gRPC logger
   unconditionally, but both are only used by the streaming instrumentation.
   A unary-only service therefore failed with "imported and not used". Gate
   those two imports on the existing hasStream flag (hoisted above the import
   block).

Verified end-to-end: generated + built + ran a GoFr gRPC server for both a
unary-only and a streaming service (no manual edits) and called it with a
real client. Added tests covering both fixes.

@Umang01-hash Umang01-hash left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified locally — this matches what #40 asked for. Renames the CLI-owned generated types to Service (NewXGoFrService, XServiceWithGofr, XServiceWrapper, RegisterXServiceWithGofr) while correctly leaving the protoc-contract symbols as Server (mustEmbedUnimplementedXServer, RegisterXServer, the generic registerServerWithGofr helper). Grep confirms no stray old names left; the test pins both halves. Build + go test ./wrap green.

Two notes:

  • This changes generated output, so existing users' main.go calls (RegisterXServerWithGofr) will need updating on regenerate — worth a line in the release notes. Also the gofr.dev gRPC docs still show the old name; worth updating there too.
  • #82 also adds wrap/template_test.go with the same createTestContext, so this and #82 conflict on that file — whichever merges second needs a quick rebase to combine them. LGTM.

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

Labels

None yet

Projects

None yet

2 participants