Documentation ¶
Overview ¶
Common helper constructs for running a gRPC server.
Index ¶
- func HealthRequest(host string, svc []string, reqIDField string, log zerolog.Logger) error
- func LogStreamInterceptor(l zerolog.Logger, fieldName string, tf TraceField) grpc.StreamServerInterceptor
- func LogUnaryInterceptor(l zerolog.Logger, fieldName string, tf TraceField) grpc.UnaryServerInterceptor
- func NewClient(server string, grpcOpts ...grpc.DialOption) (*grpc.ClientConn, error)
- func RequestID(ctx context.Context, fieldName string) string
- func TraceID(ctx context.Context, fieldName string) string
- type Option
- type RegisterServiceFunc
- type Server
- type TraceField
- type WrappedServerStream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HealthRequest ¶
HealthRequest makes a healthcheck request to gRPC service
func LogStreamInterceptor ¶
func LogStreamInterceptor(l zerolog.Logger, fieldName string, tf TraceField) grpc.StreamServerInterceptor
LogStreamInterceptor returns grpc middleware to log stream method calls
func LogUnaryInterceptor ¶
func LogUnaryInterceptor(l zerolog.Logger, fieldName string, tf TraceField) grpc.UnaryServerInterceptor
LogUnaryInterceptor returns grpc middleware to log unary method calls
func NewClient ¶
func NewClient(server string, grpcOpts ...grpc.DialOption) (*grpc.ClientConn, error)
NewClient constructs a grpc client connection
Types ¶
type Option ¶
type Option func(*Server)
An Option function can override configuration options for a server
func WithAddress ¶
WithAddress overrides the default configured listen address for a server
func WithLogger ¶
WithLogger overrides the logger instance
func WithServer ¶
WithServer overrides the grpc Server instance
type RegisterServiceFunc ¶
RegisterServiceFunc registers a service with the gRPC server returning the service name
Example:
var contentManager = func(srv *grpc.Server) string { pb.RegisterContentManagerServer(srv, &content.Manager{}) return "kit.content.v1.ContentManager" }
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server can create and stop a gRPC server
Example:
registerSvc := func(s *grpc.Server) string { healthpb.RegisterHealthServer(s, hs) return "kit.test.v1.Health" } s := grpc.New([]grpc.RegisterServiceFunc{registerSvc}) if err := s.Start(); err != nil { // handle server runtime err } if err := s.Stop(); err != nil { // handle server shutdown err }
func New ¶
func New(services []RegisterServiceFunc, opts ...Option) *Server
New creates a new gRPC server. Provide a slice of service registers and use Option functions to override defaults.
type TraceField ¶
type TraceField struct { // RequestFieldName is the name of the trace id field in the request e.g. x-b3-traceid RequestFieldName string // LoggingFieldName is the name of the trace field to send to the logger e.g. logging.googleapis.com/trace LoggingFieldName string }
TraceField provides the field names for logging the trace
type WrappedServerStream ¶
type WrappedServerStream struct { grpc.ServerStream WrappedContext context.Context }
WrappedServerStream is a thin wrapper around grpc.ServerStream that allows modifying context
func (*WrappedServerStream) Context ¶
func (w *WrappedServerStream) Context() context.Context
Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()