Add gRPC support to mains plugin#215
Merged
Merged
Conversation
This change enhances the mains plugin to support gRPC servers in addition to HTTP servers, addressing issue #209. Key changes: - Only generate HTTP server code when the service design includes HTTP endpoints - Only generate gRPC server code when the service design includes gRPC endpoints - Always generate the metrics HTTP server (health/metrics/debug endpoints) - Fix duplicate package/import declarations in generated main.go - Fix WebSocket detection bug (Stream value of 0 means no streaming, not NoStreamKind) - Conditionally import transport-specific packages based on what's actually used - Add proper OTel instrumentation for gRPC servers - Implement graceful shutdown for both HTTP and gRPC servers The plugin now: 1. Scans the DSL for HTTP and gRPC endpoint definitions 2. Conditionally generates server initialization code based on transports used 3. Manages imports efficiently (only includes websocket, grpc packages when needed) 4. Provides a unified main.go that can run HTTP-only, gRPC-only, or both transports 5. Maintains the existing single-service (services/<svc>/cmd/<svc>) and multi-service (cmd/<server>) layouts Fixes #209
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.
This PR enhances the mains plugin to support gRPC servers in addition to HTTP servers, addressing #209.
Summary
The mains plugin now intelligently generates server code based on what transports are actually defined in the Goa design:
Key Changes
1. Conditional Transport Generation
2. Fixed Bugs
package mainandimportblocks from template (now handled bycodegen.Header())3. gRPC Server Support
4. Import Management
netpackage only imported if gRPC is usedgoogle.golang.org/grpcpackages only imported if gRPC is usedgorilla/websocketonly imported if streaming endpoints are definedExample
For a service with both HTTP and gRPC endpoints:
The generated
main.gonow includes:Testing
Tested with:
All generated code compiles and runs successfully.
Fixes #209