Documentation ¶
Index ¶
- Constants
- func Dial(target string, opts ...DialOption) (*grpc.ClientConn, error)
- func GetLogger(ctx context.Context) log.Interface
- func LoggerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func SetLogger(ctx context.Context, logger log.Interface) context.Context
- type DialOption
- func WithClientTLS(serverName, serverCAPath string) DialOption
- func WithClientTLSFromParams(serverName, certPath, keyPath, serverCAPath string) DialOption
- func WithDialOptions(opts ...grpc.DialOption) DialOption
- func WithRetry(opts ...grpc_retry.CallOption) DialOption
- func WithTracer(tracer opentracing.Tracer, opts ...otgrpc.Option) DialOption
- type Server
- type ServerOption
- func TraceHealthCheck(b bool) ServerOption
- func WithAddr(addr string) ServerOption
- func WithPort(port int) ServerOption
- func WithServerTLS() ServerOption
- func WithServerTLSFromParams(certFile, keyFile string, clientCaFiles []string) ServerOption
- func WithServerTracer(tracer opentracing.Tracer) ServerOption
Constants ¶
const (
LOGGERKEY key
)
Context keys
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
func Dial(target string, opts ...DialOption) (*grpc.ClientConn, error)
Dial wraps grpc.Dial with the possibility of overriding tracing or adding retry interceptor. It is possible to add grpc.DialOptions with WithDialOptions().
func LoggerInterceptor ¶
func LoggerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
LoggerInterceptor is a gRPC server-side interceptor that logs requests.
Types ¶
type DialOption ¶
type DialOption func(*dialOptions)
DialOption represents a functional option for Dial.
func WithClientTLS ¶
func WithClientTLS(serverName, serverCAPath string) DialOption
WithClientTLS is similar to WithClientTLSFromParams, but reads client certificate and key paths from the GRPC_CLIENT_CERT and GRPC_CLIENT_KEY environment variables.
func WithClientTLSFromParams ¶
func WithClientTLSFromParams(serverName, certPath, keyPath, serverCAPath string) DialOption
WithClientTLSFromParams sets the transport credentials on dial.
func WithDialOptions ¶
func WithDialOptions(opts ...grpc.DialOption) DialOption
WithDialOptions sets the grpc.DialOptions for the underlying grpc.Dial.
func WithRetry ¶
func WithRetry(opts ...grpc_retry.CallOption) DialOption
WithRetry is a grpc dial option that adds retry logic to the requests.
func WithTracer ¶
func WithTracer(tracer opentracing.Tracer, opts ...otgrpc.Option) DialOption
WithTracer is a grpc dial option that adds a tracing middleware to the requests.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server encapsulates gRPC server
func NewServer ¶
func NewServer(cb func(*grpc.Server), opts ...ServerOption) (*Server, error)
NewServer creates a new server for gRPC
func (*Server) GracefulStop ¶
func (s *Server) GracefulStop()
GracefulStop stops the gRPC server gracefully. It stops the server to accept new connections and RPCs and blocks until all the pending RPCs are finished.
type ServerOption ¶
type ServerOption func(*options)
ServerOption define a functional options used when creating a grpc server.
func TraceHealthCheck ¶
func TraceHealthCheck(b bool) ServerOption
TraceHealthCheck is used to set if the grpc health check is traced or not. It defaults to false.
func WithAddr ¶
func WithAddr(addr string) ServerOption
WithAddr sets the listening address for the server.
func WithPort ¶
func WithPort(port int) ServerOption
WithPort sets the listening address for the server as ":<port>".
func WithServerTLS ¶
func WithServerTLS() ServerOption
WithServerTLS is similar with WithServerTLSFromParams, only it reads the server certificate, server key and client CAs paths from the GRPC_SERVER_CERT, GRPC_SERVER_KEY and GRPC_CLIENT_CA environment variables. If one of the environment variables is not set, it will exit the program.
func WithServerTLSFromParams ¶
func WithServerTLSFromParams(certFile, keyFile string, clientCaFiles []string) ServerOption
WithServerTLSFromParams enables TLS on the server using the given paths for the certificate, key and client CAs.
func WithServerTracer ¶
func WithServerTracer(tracer opentracing.Tracer) ServerOption
WithServerTracer can be used to override the default tracer.