grpc

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 33 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// CodeRPCError is a custom code to support the ErrTypeRPCError Type value
	CodeRPCError codes.Code = 1000
	// CodeBadGateway is a custom code to indicate a failure further downstream to the dependency.
	CodeBadGateway codes.Code = 1001
	// CodeUnprocessableEntity is a custom code to indicates that the server understands the content type of the request entity,
	// and the syntax of the request entity is correct, but it was unable to process the contained instructions.
	CodeUnprocessableEntity codes.Code = 1002
	// CodeNotModified is a custom code to indicate that the resource has not been modified since the version requested.
	CodeNotModified codes.Code = 1003

	// DomainRPC is a special reserved Domain for handling conversions across GRPC boundaries.
	DomainRPC errorKit.Domain = "Bread.RPC"

	// ErrTypeRPCError is a custom code specifically to report internal RPC translate
	ErrTypeRPCError errorKit.Type = 1000

	// ReasonUnknownErrorType indicates the server side error type was not supported
	ReasonUnknownErrorType grpcInterceptorReason = "Unknown_Error_Type"
)

Variables

View Source
var EmptyClientConnectionFactory = func(ctx context.Context, serviceName string) (*grpc.ClientConn, error) {
	return nil, commonError.Error{
		Err:     fmt.Errorf("service not found %s", serviceName),
		Type:    commonError.NotFound,
		Message: "error connecting to remote service",
	}
}

Functions

func AuthClientInterceptor added in v0.0.11

func AuthClientInterceptor(logger zerolog.Logger, url string, refreshInterval time.Duration, apiKey, secret string, authTimeout time.Duration, insecure bool) (grpc.UnaryClientInterceptor, error)

func ClientInterceptors added in v0.0.4

func ClientInterceptors(logger zerolog.Logger, additional ...grpc.UnaryClientInterceptor) grpc.DialOption

func ClientInterceptorsWithTracing added in v0.0.4

func ClientInterceptorsWithTracing(logger zerolog.Logger, tracer opentracing.Tracer, additional ...grpc.UnaryClientInterceptor) grpc.DialOption

func ClientTracingInterceptor added in v0.0.4

func ClientTracingInterceptor(logger zerolog.Logger, tracer opentracing.Tracer) grpc.UnaryClientInterceptor

ClientTracingInterceptor provides support for tracing gRPC client requests

func ErrorLoggingServerInterceptor added in v0.0.4

func ErrorLoggingServerInterceptor(logger zerolog.Logger) grpc.UnaryServerInterceptor

ErrorLoggingServerInterceptor logs all errors to the requestIDLogger if it's set, otherwise logs to the provided logger.

func ErrorMarshallingClientInterceptor added in v0.0.4

func ErrorMarshallingClientInterceptor(logger zerolog.Logger) grpc.UnaryClientInterceptor

ErrorMarshallingClientInterceptor is a client-side interceptor that ALWAYS returns a `gokit/errors.Error` type for easier consumption by service wrappers.

func ErrorUnmarshallingServerInterceptor added in v0.0.4

func ErrorUnmarshallingServerInterceptor(logger zerolog.Logger) grpc.UnaryServerInterceptor

ErrorUnmarshallingServerInterceptor is a server-side interceptor that attempts to always returns a Status with LocalizedMessage details for easier consumption by service clients.

func FromContextMetaData added in v0.0.11

func FromContextMetaData(ctx context.Context) (identity.Identity, error)

func IdentityClientInterceptor added in v0.0.11

func IdentityClientInterceptor(logger zerolog.Logger) grpc.UnaryClientInterceptor

func IdentityServerInterceptor added in v0.0.11

func IdentityServerInterceptor(logger zerolog.Logger) grpc.UnaryServerInterceptor

func MapCodeToType added in v0.0.4

func MapCodeToType(logger zerolog.Logger, code codes.Code) errorKit.Type

MapCodeToType takes a grpc error code and returns the appropriate gokit error type for it.

func MapToCode added in v0.0.4

func MapToCode(logger zerolog.Logger, kitError errorKit.Error) codes.Code

MapToCode maps to gokit error to grpc code if it exists or else maps tp `codes.Unknown`

func MapToStatus added in v0.0.4

func MapToStatus(logger zerolog.Logger, kitError errorKit.Error) (*status.Status, error)

MapToStatus maps the kit error to grpc status

func RequestIDClientInterceptor added in v0.0.4

func RequestIDClientInterceptor(logger zerolog.Logger) grpc.UnaryClientInterceptor

RequestIDClientInterceptor sets an existing RequestID from the Go context onto the GRPC metadata for passing to the server.

func RequestIDLoggerClientInterceptor added in v0.0.4

func RequestIDLoggerClientInterceptor(logger zerolog.Logger) grpc.UnaryClientInterceptor

RequestIDLoggerClientInterceptor attempts to set the incoming context, the Logger returned from requestidlogger.FromContext.

func RequestIDLoggerServerInterceptor added in v0.0.4

func RequestIDLoggerServerInterceptor(parentLogger zerolog.Logger) grpc.UnaryServerInterceptor

RequestIDLoggerServerInterceptor uses the requestidlogger package and the provided parentLogger to set a new Child Logger on the context that has the RequestID on its context.

func RequestIDServerInterceptor added in v0.0.4

func RequestIDServerInterceptor(logger zerolog.Logger) grpc.UnaryServerInterceptor

RequestIDServerInterceptor sets an existing RequestID from the GRPC context metadata onto the context, and uses the new context on the provided UnaryHandler parameter. If there is no RequestID, a new one is generated, and an error is logged to the provided logger.

func ServerInterceptors added in v0.0.4

func ServerInterceptors(logger zerolog.Logger, additional ...grpc.UnaryServerInterceptor) grpc.ServerOption

func ServerInterceptorsWithTracing added in v0.0.4

func ServerInterceptorsWithTracing(logger zerolog.Logger, tracer opentracing.Tracer, additional ...grpc.UnaryServerInterceptor) grpc.ServerOption

func ServerTracingInterceptor added in v0.0.4

func ServerTracingInterceptor(logger zerolog.Logger, tracer opentracing.Tracer) grpc.UnaryServerInterceptor

ServerTracingInterceptor provides support for tracing gRPC server requests

Types

type Client added in v0.0.8

type Client struct {
	// contains filtered or unexported fields
}

func NewClient added in v0.0.8

func NewClient(register func(conn *grpc.ClientConn), address string, errors chan<- error, opt ...grpc.DialOption) *Client

func (*Client) Disconnect added in v0.0.8

func (c *Client) Disconnect() error

type ClientConnectionFactory added in v0.0.8

type ClientConnectionFactory func(ctx context.Context, serviceName string) (*grpc.ClientConn, error)

type ClientMap added in v0.0.8

type ClientMap struct {
	// contains filtered or unexported fields
}

func NewClientMap added in v0.0.8

func NewClientMap(configMap map[string]config.GRPCClient, opts ...grpc.DialOption) *ClientMap

func (*ClientMap) Close added in v0.0.8

func (c *ClientMap) Close() error

func (*ClientMap) GetClientConnection added in v0.0.8

func (c *ClientMap) GetClientConnection(ctx context.Context, serviceName string) (*grpc.ClientConn, error)

type Registrar

type Registrar func(register func(mux *grpc.Server))

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(register func(server *grpc.Server), address string, errors chan<- error, options ...ServerOption) *Server

func NewUnstartedServer

func NewUnstartedServer(options ...ServerOption) *Server

func (*Server) Address

func (s *Server) Address() string

func (*Server) RegisterService

func (s *Server) RegisterService(register func(server *grpc.Server))

func (*Server) Start

func (s *Server) Start(address string, errors chan<- error) error

func (*Server) Stop

func (s *Server) Stop() error

func (*Server) StopWithTimeout

func (s *Server) StopWithTimeout(timeout time.Duration) error

type ServerOption

type ServerOption func(options *serverOptions)

func EnableTracing

func EnableTracing(enabled bool) ServerOption

func GRPCOptions

func GRPCOptions(grpcOptions ...grpc.ServerOption) ServerOption

func ShutdownTimeout

func ShutdownTimeout(timeout time.Duration) ServerOption

Jump to

Keyboard shortcuts

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