Documentation ¶
Index ¶
- func EncryptedErrorScrubber(key string) func(error) error
- func ListenAndServe(ctx context.Context, addr string, srv *grpc.Server) error
- func New(cfg *Config) (*grpc.Server, error)
- func NoopErrorScrubber(err error) error
- func SimpleErrorScrubber(err error) error
- func StreamErrorInterceptor(scrubber func(error) error) grpc.StreamServerInterceptor
- func StreamServerInterceptor() grpc.StreamServerInterceptor
- func UnaryErrorInterceptor(scrubber func(error) error) grpc.UnaryServerInterceptor
- func UnaryServerInterceptor() grpc.UnaryServerInterceptor
- type Config
- type Option
- func WithCredentials(cert, key, ca string) Option
- func WithErrorScrubbing(scrubber func(error) error) Option
- func WithLogging(app string) Option
- func WithMDLogging() Option
- func WithMetrics() Option
- func WithRecovery() Option
- func WithReflection() Option
- func WithTracing(serverDeprecated, serviceName string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncryptedErrorScrubber ¶ added in v0.2.0
EncryptedErrorScrubber replaces unknown or internal errors with a generic error object. The original error message is encrypted and added to the error message in the status.Details
func ListenAndServe ¶
ListenAndServe serves an gRPC server over TCP
func New ¶
New creates a new gRPC server with the given options
Example:
srv, _ := server.New(&server.Config{ Options: []server.Option{ server.WithCredentials("cert.pem","key.pem","ca.pem"), server.WithTracing("opentracing:6818", "my-service") server.WithLogging("my-service"), server.WithMetrics("my-service"), server.WithRecovery(), server.WithReflection()), }, Extras: []grpc.ServerOption{ grpc.MaxReceiveMsgSize(4<<12), grpc.MaxSendMsgSize(4<<12), }, Register: func(srv, *grpc.Server){ myservice.RegisterMyFooServiceServer(srv, myFooServiceImpl) myservice.RegisterMyBarServiceServer(srv, myBarServiceImpl) }, }
server.ListenAndServe(":3001", srv)
func NoopErrorScrubber ¶ added in v0.2.0
NoopErrorScrubber returns the error unmodified, this can be useful in debug or development environments
func SimpleErrorScrubber ¶ added in v0.2.0
SimpleErrorScrubber replaces unknown or internal errors with a generic error object
func StreamErrorInterceptor ¶ added in v0.2.0
func StreamErrorInterceptor(scrubber func(error) error) grpc.StreamServerInterceptor
StreamErrorInterceptor ensure internal or unknown errors do not leak information
func StreamServerInterceptor ¶
func StreamServerInterceptor() grpc.StreamServerInterceptor
StreamServerInterceptor returns a new streaming server interceptor that adds logrus.Entry to the context.
func UnaryErrorInterceptor ¶ added in v0.2.0
func UnaryErrorInterceptor(scrubber func(error) error) grpc.UnaryServerInterceptor
UnaryErrorInterceptor ensures internal or unknown errors do not leak information
func UnaryServerInterceptor ¶
func UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that adds logrus.Entry to the context.
Types ¶
type Config ¶
type Config struct { Options []Option Extras []grpc.ServerOption Register func(*grpc.Server) }
Config contains the configuration for your server. See New() for example usage
type Option ¶
type Option interface { GetOptions() (grpc.ServerOption, grpc.StreamServerInterceptor, grpc.UnaryServerInterceptor, error) PostProcess(s *grpc.Server) error }
Option is the interface for the package supplied configuration helpers
func WithCredentials ¶
WithCredentials configures the server to use the given cert/key combination. If a ca file is supplied it is used to verify clients which now are required to have a certificate.
func WithErrorScrubbing ¶ added in v0.2.0
WithErrorScrubbing ensures that internal or unknown errors do not leak information. You may pass a function to customize the scrubbing behavior. The package provides two simple scrubbers: SimpleErrorScrubber, EncryptedErrorScrubber, and NoopErrorScrubber for convenience.
func WithLogging ¶
WithLogging configures a logrus logger to log all gRPC requests with duration and return status
func WithMDLogging ¶
func WithMDLogging() Option
WithMDLogging configures a logrus logger to log all gRPC requests with duration and return status
func WithMetrics ¶
func WithMetrics() Option
WithMetrics configures the server to collect usage metrics in prometheus format
func WithRecovery ¶
func WithRecovery() Option
WithRecovery recovers the server from panics caused inside of the gRPC calls
func WithReflection ¶
func WithReflection() Option
WithReflection configures the server to provide an API for external tools to get informations about the used services and types. It enables a service which returns the proto definitions for the methods, so that you can use tools like [grpcurl](https://github.com/fullstorydev/grpcurl) without the need to supply the protofile to interact with the service.
func WithTracing ¶
WithTracing configures the server to support tracing in the opentracing format. It attaches a root span to the context of all incoming requests.
The tracer is configured via the JAEGER_* env variables.
The server variable is deprecated and will be ignored.