server

package
v2.17.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 35 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodeGenRequestFieldExtractor added in v2.2.4

func CodeGenRequestFieldExtractor(fullMethod string, req interface{}) map[string]interface{}

CodeGenRequestFieldExtractor is a function that relies on code-generated functions that export log fields from requests. These are usually coming from a protoc-plugin that generates additional information based on custom field options.

func DecodeToJsonObject added in v2.7.5

func DecodeToJsonObject(m interface{}) map[string]interface{}

func DefaultCodeToLevel added in v2.2.4

func DefaultCodeToLevel(code codes.Code) zapcore.Level

DefaultCodeToLevel is the default implementation of gRPC return codes and interceptor log level for server side.

func FillLoggerWithDeviceIDHrefCorrelationID added in v2.7.5

func FillLoggerWithDeviceIDHrefCorrelationID(logger log.Logger, req interface{}) log.Logger

func MakeDefaultMessageProducer added in v2.2.4

func MakeDefaultMessageProducer(logger *zap.Logger) func(ctx context.Context, msg string, level zapcore.Level, code codes.Code, err error, duration zapcore.Field)

func MakeDefaultOptions

func MakeDefaultOptions(auth pkgGrpc.AuthInterceptors, logger log.Logger, tracerProvider trace.TracerProvider) ([]grpc.ServerOption, error)

func NewAuth

func NewAuth(validator pkgGrpc.Validator, opts ...Option) pkgGrpc.AuthInterceptors

func NewLogStreamServerInterceptor added in v2.7.5

func NewLogStreamServerInterceptor(logger log.Logger, dumpBody bool) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that adds zap.Logger to the context.

func NewLogUnaryServerInterceptor added in v2.7.5

func NewLogUnaryServerInterceptor(logger log.Logger, dumpBody bool) grpc.UnaryServerInterceptor

Types

type AuthorizationConfig

type AuthorizationConfig struct {
	OwnerClaim       string `yaml:"ownerClaim" json:"ownerClaim"`
	validator.Config `yaml:",inline" json:",inline"`
}

func (*AuthorizationConfig) Validate

func (c *AuthorizationConfig) Validate() error

type Config

type Config struct {
	Addr string `yaml:"address" json:"address"`
	// SendMsgSize is the maximum size of a message the server can send. If <=0, a default of 4MB will be used.
	SendMsgSize int `yaml:"sendMsgSize" json:"sendMsgSize"`
	// RecvMsgSize is the maximum size of a message the server can receive. If <=0, a default of 4MB will be used.
	RecvMsgSize       int                     `yaml:"recvMsgSize" json:"recvMsgSize"`
	EnforcementPolicy EnforcementPolicyConfig `yaml:"enforcementPolicy" json:"enforcementPolicy"`
	KeepAlive         KeepAliveConfig         `yaml:"keepAlive" json:"keepAlive"`
	TLS               server.Config           `yaml:"tls" json:"tls"`
	Authorization     AuthorizationConfig     `yaml:"authorization" json:"authorization"`
}

func (*Config) Validate

func (c *Config) Validate() error

type EnforcementPolicyConfig

type EnforcementPolicyConfig struct {
	// MinTime is the minimum amount of time a client should wait before sending
	// a keepalive ping.
	MinTime time.Duration `yaml:"minTime" json:"minTime"` // The current default value is 5 minutes.
	// If true, server allows keepalive pings even when there are no active
	// streams(RPCs). If false, and client sends ping when there are no active
	// streams, server will send GOAWAY and close the connection.
	PermitWithoutStream bool `yaml:"permitWithoutStream" json:"permitWithoutStream"` // false by default.
}

EnforcementPolicyConfig is used to set keepalive enforcement policy on the server-side. Server will close connection with a client that violates this policy.

func (EnforcementPolicyConfig) ToGrpc

type GetDeviceIDPb added in v2.2.4

type GetDeviceIDPb interface {
	GetDeviceId() string
}

type KeepAliveConfig

type KeepAliveConfig struct {
	// MaxConnectionIdle is a duration for the amount of time after which an
	// idle connection would be closed by sending a GoAway. Idleness duration is
	// defined since the most recent time the number of outstanding RPCs became
	// zero or the connection establishment.
	MaxConnectionIdle time.Duration `yaml:"maxConnectionIdle" json:"maxConnectionIdle"` // The current default value is infinity.
	// MaxConnectionAge is a duration for the maximum amount of time a
	// connection may exist before it will be closed by sending a GoAway. A
	// random jitter of +/-10% will be added to MaxConnectionAge to spread out
	// connection storms.
	MaxConnectionAge time.Duration `yaml:"maxConnectionAge" json:"maxConnectionAge"` // The current default value is infinity.
	// MaxConnectionAgeGrace is an additive period after MaxConnectionAge after
	// which the connection will be forcibly closed.
	MaxConnectionAgeGrace time.Duration `yaml:"maxConnectionAgeGrace" json:"maxConnectionAgeGrace"` // The current default value is infinity.
	// After a duration of this time if the server doesn't see any activity it
	// pings the client to see if the transport is still alive.
	// If set below 1s, a minimum value of 1s will be used instead.
	Time time.Duration `yaml:"time" json:"time"` // The current default value is 2 hours.
	// After having pinged for keepalive check, the server waits for a duration
	// of Timeout and if no activity is seen even after that the connection is
	// closed.
	Timeout time.Duration `yaml:"timeout" json:"timeout"` // The current default value is 20 seconds.
}

func (KeepAliveConfig) ToGrpc

type Option

type Option func(*config)

func WithDisabledTokenForwarding

func WithDisabledTokenForwarding() Option

func WithWhiteListedMethods

func WithWhiteListedMethods(method ...string) Option

type Server

type Server struct {
	*grpc.Server
	// contains filtered or unexported fields
}

Server handles gRPC requests to the service.

func New

func New(config Config, fileWatcher *fsnotify.Watcher, logger log.Logger, opts ...grpc.ServerOption) (*Server, error)

func NewServer

func NewServer(addr string, opts ...grpc.ServerOption) (*Server, error)

NewServer instantiates a gRPC server. When passing addr with an unspecified port or ":", use Addr().

func (*Server) AddCloseFunc

func (s *Server) AddCloseFunc(f func())

AddCloseFunc adds a function to be called by the Close method. This eliminates the need for wrapping the Server.

func (*Server) Addr

func (s *Server) Addr() string

func (*Server) Close

func (s *Server) Close() error

Close stops the gRPC server. It immediately closes all open connections and listeners. It cancels all active RPCs on the server side and the corresponding pending RPCs on the client side will get notified by connection errors.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts serving and blocks.

func (*Server) SetGracefulStop added in v2.13.1

func (s *Server) SetGracefulStop(gracefulStop bool)

Jump to

Keyboard shortcuts

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