scrpc

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
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 GetLogger

func GetLogger(ctx context.Context) log.Interface

GetLogger returns a logger scoped to request

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.

func SetLogger

func SetLogger(ctx context.Context, logger log.Interface) context.Context

SetLogger sets logger in a context

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.

func (*Server) Run

func (s *Server) Run() error

Run starts gRPC server.

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.

Jump to

Keyboard shortcuts

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