grpckit

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCEndpointRegistrator

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

GRPCEndpointRegistrator abstracts a mechanics of registering the gRPC service in the 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[config]) (*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 config] 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[config]

WithLogger sets the server logger.

func WithStreamInterceptors

func WithStreamInterceptors(interceptors ...midkit.StreamInterceptor) Option[config]

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

func WithUnaryInterceptors

func WithUnaryInterceptors(interceptors ...midkit.UnaryInterceptor) Option[config]

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

Jump to

Keyboard shortcuts

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