Skip to content

feat: add gRPC server support (Closes #100)#116

Open
ljluestc wants to merge 2 commits intoxinliangnote:masterfrom
ljluestc:fix/issue-100-grpc-support-clarification
Open

feat: add gRPC server support (Closes #100)#116
ljluestc wants to merge 2 commits intoxinliangnote:masterfrom
ljluestc:fix/issue-100-grpc-support-clarification

Conversation

@ljluestc
Copy link
Copy Markdown

@ljluestc ljluestc commented Apr 9, 2026

Summary

Adds gRPC server support to go-gin-api, addressing #100 which reported that gRPC functionality was missing from the codebase.

Changes

New Files

  • api/proto/service.proto — Protobuf definitions for HealthService and HelloService
  • internal/grpc/pb/ — Generated Go protobuf + gRPC stubs (message types and server registration)
  • internal/grpc/interceptor/interceptor.go — Unary server interceptors:
    • UnaryLogInterceptor — Logs every gRPC call with method name, duration, and errors (using zap)
    • UnaryRecoveryInterceptor — Recovers from panics and returns codes.Internal
  • internal/grpc/service/health.goHealthService implementation (always returns SERVING)
  • internal/grpc/service/hello.goHelloService implementation with trace ID propagation via gRPC metadata
  • internal/grpc/server/server.go — gRPC server setup with chained interceptors and service registration

Modified Files

  • main.go — Initializes gRPC server on :9998, runs alongside HTTP server, adds graceful shutdown hook
  • configs/constants.go — Adds ProjectGRPCPort = ":9998"
  • go.mod / go.sum — Adds google.golang.org/grpc v1.46.0
  • README.md — Documents gRPC as an integrated component

Architecture

HTTP Server (:9999)  ──►  gin engine (existing)
gRPC Server (:9998)  ──►  grpc.Server
                           ├── HealthService.Check
                           └── HelloService.SayHello
                           Interceptors: Recovery → Logging

Testing

# Health check
grpcurl -plaintext localhost:9998 api.HealthService/Check

# Hello service
grpcurl -plaintext -d '{"name": "World"}' localhost:9998 api.HelloService/SayHello

Conversation link

Co-Authored-By: Oz oz-agent@warp.dev

ljluestc and others added 2 commits April 9, 2026 08:20
Clarify that go-gin-api currently focuses on HTTP/REST, GraphQL, and WebSocket, and does not include built-in gRPC server or .proto definitions.

Refs xinliangnote#100

Co-Authored-By: Oz <oz-agent@warp.dev>
Closes xinliangnote#100

- Add protobuf definitions under api/proto/
- Implement gRPC server with unary interceptors (logging + panic recovery)
- Add HealthService (health check) and HelloService (sample) implementations
- Integrate gRPC server lifecycle into main.go (startup + graceful shutdown)
- gRPC server listens on port :9998 alongside HTTP on :9999
- Add google.golang.org/grpc dependency
- Update README to document gRPC support

Co-Authored-By: Oz <oz-agent@warp.dev>
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.

1 participant