servers

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GRPCMaxConcurrentStreams = 1000000
)

Variables

This section is empty.

Functions

func StandardTracer

func StandardTracer(cfg *BaseServerConfig) (trace.TracerProvider, error)

StandardTracer - Setup standard OTEL based tracer

Types

type BaseServerConfig

type BaseServerConfig struct {
	ServiceName      string
	TLS              auth.TLSConfigOptions
	Tracing          tracing.OTELConfig
	SwaggerFile      string
	Version          string
	ShutdownEndpoint string
}

func (*BaseServerConfig) AddServerFlags

func (cfg *BaseServerConfig) AddServerFlags(cmd *cobra.Command) bool

func (*BaseServerConfig) SetAdminRoutes

func (cfg *BaseServerConfig) SetAdminRoutes(mux *http.ServeMux, shutdownHandler http.Handler)

SetAdminRoutes sets up common routes for all services.

func (*BaseServerConfig) SetupTLSConfig

func (cfg *BaseServerConfig) SetupTLSConfig() (tls.Certificate, *x509.CertPool, error)

SetupTLSConfig sets up the certificates and cert-pool based on the tls files provided

type CustomErrorHandlerFunc

type CustomErrorHandlerFunc func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler,
	w http.ResponseWriter, r *http.Request, err error)

type GRPCConfig

type GRPCConfig struct {
	*BaseServerConfig
	GRPCAddr  string
	HTTPAddr  string
	AdminAddr string
	// protobuf generated server registration function
	RegisterServer RegisterServerFunc `json:"-"`
	// REST gateway generated handler registration function
	RegisterHandler RegisterHandlerFunc `json:"-"`
	// use the provided mux for http instead of the default grpc-gateway mux
	HTTPEndpointOverride HTTPEndpointOverrideFunc `json:"-"`
	// pre-serve callback function to customize server setting before it is served
	PreServeCallback PreServeCallbackFunc `json:"-"`
	// additional GRPC server options
	ExtraServerOpts []grpc.ServerOption `json:"-"`
	// additional HTTP connection dial options
	ExtraHTTPDialOpts []grpc.DialOption `json:"-"`
	// additional admin http handlers
	AdditionalHttpHandlers map[string]http.Handler `json:"-"`
	// allow additional headers from requests
	AdditionalHeaders []string `json:"-"`
	// custom error handler function
	CustomErrorHandler  CustomErrorHandlerFunc `json:"-"`
	TerminationCallback func()                 `json:"-"`
	// set explicit http endpoints to serve health information
	HttpHealthEndpointOverride []string `json:"-"`
	// add additional servers
	AdditionalServers []ServerFuncPair
}

GRPCConfig holds basic config required to setup a GRPC server

func (*GRPCConfig) AddServerFlags

func (gc *GRPCConfig) AddServerFlags(cmd *cobra.Command) bool

AddServerFlags if a helper function to add common flags to server command Returns true if addition of flags was successful

func (*GRPCConfig) SetupTLSConfig

func (gc *GRPCConfig) SetupTLSConfig() (tls.Certificate, *x509.CertPool, error)

SetupTLSConfig sets up the certificates and cert-pool based on the tls files provided

type HTTPEndpointOverrideFunc

type HTTPEndpointOverrideFunc func(mux *runtime.ServeMux) *runtime.ServeMux

HTTPEndpointOverrideFunc : override for grpc-gateway mux - useful for overriding some endpoints and let grpc-gateway handle the rest of the endpoints by default

type Option

type Option func(server *grpcServer)

func WithAdditionalHTTPHandlers

func WithAdditionalHTTPHandlers(handlers map[string]http.Handler) Option

func WithAdditionalRequestHeaders

func WithAdditionalRequestHeaders(headers []string) Option

func WithAdditionalServers

func WithAdditionalServers(additionalServers ...ServerFuncPair) Option

func WithCustomErrorHandler

func WithCustomErrorHandler(customErrorHandler CustomErrorHandlerFunc) Option

func WithExtraHTTPDialOpts

func WithExtraHTTPDialOpts(dialOpts []grpc.DialOption) Option

func WithExtraServerOpts

func WithExtraServerOpts(serverOpts []grpc.ServerOption) Option

func WithHTTPEndpointOverride

func WithHTTPEndpointOverride(httpEndpointFunc HTTPEndpointOverrideFunc) Option

func WithHttpHealthEndpoints

func WithHttpHealthEndpoints(healthEndpoints ...string) Option

func WithLogger

func WithLogger(logger log.Logger) Option

func WithPreServeCallback

func WithPreServeCallback(cbFunc PreServeCallbackFunc) Option

func WithRegisterHandler

func WithRegisterHandler(handlerFunc RegisterHandlerFunc) Option

func WithRegisterServer

func WithRegisterServer(serverFunc RegisterServerFunc) Option

func WithTerminationCallback

func WithTerminationCallback(terminationCallbackFunc func()) Option

func WithTracer

func WithTracer(tracer trace.TracerProvider) Option

type PreServeCallbackFunc

type PreServeCallbackFunc func(s *grpc.Server) error

PreServeCallbackFunc : callback to customize any settings of the server before it is served

type RegisterHandlerFunc

type RegisterHandlerFunc func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterHandlerFunc : register single handler function

type RegisterServerFunc

type RegisterServerFunc func(s *grpc.Server)

RegisterServerFunc : register grpc server function

type Server

type Server interface {
	Setup() error
	Run() error
}

func NewGRPCServer

func NewGRPCServer(config *GRPCConfig, opts ...Option) Server

NewGRPCServer - factory method for grpc based services

type ServerFuncPair

type ServerFuncPair struct {
	Execute   func() error
	Interrupt func(error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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