grpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2018 License: MIT Imports: 22 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(ctx context.Context, addr string, srv *grpc.Server) error

ListenAndServe serves an gRPC server over TCP

func New

func New(cfg *Config) (*grpc.Server, error)

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 StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that adds logrus.Entry to the context.

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

func WithCredentials(cert, key, ca string) Option

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 WithLogging

func WithLogging(app string) Option

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

func WithTracing(server, serviceName string) Option

WithTracing configures the server to support tracing in the opentracing format. It attaches a root span to the context of all incoming requests and configures the tracer to send the traces to the configured opentracing server.

Directories

Path Synopsis
Package test is a generated protocol buffer package.
Package test is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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