grpckit

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggingInterceptor added in v0.2.7

func LoggingInterceptor(logger *slog.Logger) grpc.UnaryServerInterceptor

LoggingInterceptor is a gRPC unary server interceptor that logs method calls and their durations. It takes a logger instance as input and returns a UnaryServerInterceptor function.

func MetricsInterceptor added in v0.2.7

func MetricsInterceptor() grpc.UnaryServerInterceptor

Types

type GRPCEndpointRegistrator

type GRPCEndpointRegistrator interface {
	Mount(server *grpc.Server)
}

GRPCEndpointRegistrator abstracts a mechanics of registering the gRPC service in the gRPC server.

type ListenerConfig added in v0.2.15

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

ListenerConfig represents a struct that holds the configuration options for a gRPC server.

type ListenerGRPC

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

ListenerGRPC represents a struct that encapsulates a gRPC server listener.

func NewListenerGRPC

func NewListenerGRPC(addr string, options ...Option[ListenerConfig]) (*ListenerGRPC, error)

NewListenerGRPC creates a new ListenerGRPC instance by creating a gRPC listener using a given address. It applies all the options to a default `applyOptionsGRPC` instance and sets the server options with the provided unary and stream interceptors. Finally, it returns the ListenerGRPC instance and potential error.

func (*ListenerGRPC) Mount

func (l *ListenerGRPC) Mount(handlers ...GRPCEndpointRegistrator)

Mount the given handlers to the listener gRPC server.

func (*ListenerGRPC) Serve

func (l *ListenerGRPC) Serve(ctx context.Context) error

type Option

type Option[T ListenerConfig] func(o *T)

Option implements functional options pattern for the ListenerGRPC type. Represents a function which receive a pointer to the generic struct that represents a part of ListenerGRPC configuration and changes it default values to the given ones.

See the applyOptionsGRPC function to understand the configuration behaviour. Option functions should only be passed to ListenerGRPC constructor function NewListenerGRPC.

func WithLogger

func WithLogger(logger *slog.Logger) Option[ListenerConfig]

WithLogger sets the server logger.

func WithStreamInterceptors

func WithStreamInterceptors(interceptors ...StreamInterceptor) Option[ListenerConfig]

WithStreamInterceptors is a function that takes a variable number of StreamInterceptor functions and returns an Option[ListenerConfig]. This function is used to add StreamInterceptors to the streamInterceptors field of the ListenerConfig struct.

func WithUnaryInterceptors

func WithUnaryInterceptors(interceptors ...UnaryInterceptor) Option[ListenerConfig]

WithUnaryInterceptors is a function that takes a variable number of UnaryInterceptor functions and returns an Option[ListenerConfig]. This function is used to add UnaryInterceptors to the unaryInterceptors field of the ListenerConfig struct.

type StreamInterceptor added in v0.2.7

type StreamInterceptor = grpc.StreamServerInterceptor

StreamInterceptor is an alias for grpc.StreamServerInterceptor. It is used as a middleware to intercept streaming RPC calls in a gRPC server.

type UnaryInterceptor added in v0.2.7

type UnaryInterceptor = grpc.UnaryServerInterceptor

UnaryInterceptor is an alias for grpc.UnaryServerInterceptor. It is used as a middleware to intercept unary RPC calls in a gRPC server.

Jump to

Keyboard shortcuts

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