Documentation
¶
Overview ¶
Package grpcserver bootstraps a gRPC server with the same cross-cutting concerns as the REST stack — panic recovery, trace-id injection, structured access logging, Prometheus metrics, and errs->status mapping — and exposes it as a worker.Runnable so it can be supervised alongside the HTTP server and background workers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Addr is the listen address, e.g. ":9090".
Addr string
// ShutdownTimeout bounds graceful shutdown before a hard stop (default 10s).
ShutdownTimeout time.Duration
// EnableReflection turns on server reflection (handy for grpcurl in dev).
EnableReflection bool
// MetricsNamespace prefixes the gRPC metric names (default "grpc").
MetricsNamespace string
// MaxRecvMsgSize / MaxSendMsgSize override the 4 MiB defaults (bytes).
MaxRecvMsgSize int
MaxSendMsgSize int
// NumStreamWorkers bounds the pool of goroutines serving streams; 0 spawns
// one goroutine per stream (the gRPC default).
NumStreamWorkers uint32
// allocations under load.
SharedWriteBuffer bool
// Keepalive tunes connection liveness; zero values fall back to gRPC defaults.
Keepalive KeepaliveConfig
}
Config configures the gRPC server.
type KeepaliveConfig ¶
type KeepaliveConfig struct {
MaxConnectionIdle time.Duration
MaxConnectionAge time.Duration
Time time.Duration
Timeout time.Duration
MinTime time.Duration
PermitWithoutStream bool
}
KeepaliveConfig mirrors the gRPC keepalive server parameters and enforcement policy. Zero values are left at gRPC defaults.
type Option ¶
type Option func(*options)
Option customizes the server.
func WithMetrics ¶
func WithMetrics(reg prometheus.Registerer) Option
WithMetrics registers gRPC collectors on reg (e.g. metrics.Metrics.Registry).
func WithTracer ¶
WithTracer sets the tracer used for trace-id injection. Defaults to a no-op.
func WithUnaryInterceptors ¶
func WithUnaryInterceptors(in ...grpc.UnaryServerInterceptor) Option
WithUnaryInterceptors appends application interceptors, applied after the built-in ones (closest to the handler).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps a *grpc.Server and implements worker.Runnable.
func (*Server) Serve ¶
Serve serves on the provided listener until Stop. It is useful for tests (e.g. a bufconn listener) and for callers that manage their own listener.
func (*Server) ServiceRegistrar ¶
func (s *Server) ServiceRegistrar() grpc.ServiceRegistrar
ServiceRegistrar returns the registrar used to register gRPC services, e.g. widgetv1.RegisterWidgetServiceServer(s.ServiceRegistrar(), handler).