grpcserver

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricApiRequestCount        = "ApiRequestCount"
	MetricApiRequestResponseTime = "ApiRequestResponseTime"
	MetricDimensionFullMethod    = "full_method"
)

Variables

This section is empty.

Functions

func New

func New(name string, definer ServiceDefiner, middlewares ...MiddlewareFactory) kernel.ModuleFactory

New returns a kernel.ModuleFactory for the Server kernel.Module.

func NewHealthServer

func NewHealthServer(logger log.Logger, cancelFunc context.CancelFunc) *healthServer

NewHealthServer returns a new HealthServer.

func NewStatsHandler

func NewStatsHandler(logger log.Logger, settings *Settings) *statsHandler

Types

type Definitions

type Definitions []definition

Definitions is a collection that is used to initialize the Server.

During the initialisation the Registrant function will be called.

func (*Definitions) Add

func (s *Definitions) Add(name string, registrant Registrant) *Definitions

Add a new definition by providing the service name and the registrant.

func (*Definitions) AddWithHealthCheckCallback

func (s *Definitions) AddWithHealthCheckCallback(name string, registrant Registrant, healthCheckCallback HealthCheckCallback) *Definitions

AddWithHealthCheckCallback a new definition by providing the service name, the registrant and the HealthCheckCallback.

type Health

type Health struct {
	// Enabled determines if the default health.checks will be used
	// the default health-checks utilizes the google.golang.org/grpc/health/grpc_health_v1 pkg.
	Enabled bool `cfg:"enabled" default:"true"`
}

Health settings of the Server.

type HealthCheckCallback

type HealthCheckCallback func(ctx context.Context) protobuf.HealthCheckResponse_ServingStatus

HealthCheckCallback the signature of the HealthCheckCallback.

type Middleware

type Middleware grpc.UnaryServerInterceptor

type MiddlewareFactory

type MiddlewareFactory func(logger log.Logger) Middleware

type Registrant

type Registrant func(server *grpc.Server) error

Registrant is a function callback that receives a cancelFunc and a grpc.Server and should be implemented to add the gRPC services to the grpc.Server.

type Server

type Server struct {
	kernel.EssentialModule
	kernel.ServiceStage
	// contains filtered or unexported fields
}

Server a basic grpc.Server wrapper that allows also can have a basic Health Check functionality.

func NewWithInterfaces

func NewWithInterfaces(ctx context.Context, logger log.Logger, definitions *Definitions, s *Settings, middlewares ...MiddlewareFactory) (*Server, error)

NewWithInterfaces receives the interfaces required to create a Server.

func (*Server) Addr

func (g *Server) Addr() net.Addr

Addr Returns the net.Addr of the Server.

func (*Server) Run

func (g *Server) Run(ctx context.Context) error

Run starts the Server kernel.Module, listens to the port configured and gracefully shuts down when the context is closed or if the HealthChecks are enabled when a service becomes unhealthy.

type ServiceDefiner

type ServiceDefiner func(ctx context.Context, config cfg.Config, logger log.Logger) (*Definitions, error)

ServiceDefiner is used to initialise the Server module.

This function is used to initialise your dependencies i.e. the services.

type ServiceHealthCallback

type ServiceHealthCallback struct {
	ServiceName         string
	HealthCheckCallback HealthCheckCallback
}

ServiceHealthCallback definition.

type Settings

type Settings struct {
	// Port where the grpc.Server will be listening to.
	Port string `cfg:"port" default:"8081"`
	// Health related settings.
	Health Health `cfg:"health"`
	// Statistics related settings.
	Stats Stats `cfg:"stats"`
}

Settings of the Server.

type Stats

type Stats struct {
	// Enabled defines if the statistics handler is enabled.
	Enabled bool `cfg:"enabled" default:"true"`
	// LogLevel defines the log level for the statistics logs
	LogLevel string `cfg:"log_level" default:"debug" validate:"oneof=debug info"`
	// LogPayload defines whether to log the incoming and outgoing payloads of a gRPC method.
	LogPayload bool `cfg:"log_payload" default:"false"`
	// LogData defines whether to log the incoming and outgoing raw data of a gRPC method.
	LogData bool `cfg:"log_data" default:"false"`
	// Channel to log the statistics to.
	Channel string `cfg:"channel" default:"grpc_stats"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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