example-grpc

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 6 Imported by: 0

README

Mithril gRPC Example

This example demonstrates gRPC support in the Mithril framework.

Prerequisites

Install the Protocol Buffer compiler and Go plugins:

# Install protoc
# macOS
brew install protobuf

# Linux
apt-get install -y protobuf-compiler

# Install Go plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

Generate Code from Proto Files

cd example-grpc
protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    proto/hello.proto

Running the Example

# Start the gRPC server
go run example-grpc/main.go

The server will start on localhost:50051.

Testing with grpcurl

Install grpcurl:

# macOS
brew install grpcurl

# Linux
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
List services:
grpcurl -plaintext localhost:50051 list
Call SayHello:
grpcurl -plaintext -d '{"name": "Mithril"}' localhost:50051 hello.HelloService/SayHello
Call SayHelloStream:
grpcurl -plaintext -d '{"name": "Mithril"}' localhost:50051 hello.HelloService/SayHelloStream

Features Demonstrated

  • gRPC server setup with Mithril
  • Unary RPC (SayHello)
  • Server streaming RPC (SayHelloStream)
  • Middleware/Interceptors:
    • Logging
    • Recovery (panic handling)
    • Authentication
  • Service reflection for grpcurl
  • Configuration from environment

Production Usage

For production deployments:

  1. TLS/SSL: Enable TLS for secure communication
  2. Load Balancing: Use gRPC load balancing strategies
  3. Monitoring: Integrate with Prometheus for metrics
  4. Tracing: Add OpenTelemetry for distributed tracing
  5. Health Checks: Implement gRPC health checking protocol
  6. Authentication: Use JWT or mTLS for authentication

Next Steps

  • Add more complex service definitions
  • Implement bidirectional streaming
  • Add custom metadata handling
  • Integrate with database
  • Add rate limiting
  • Implement circuit breakers

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL