middleware

package
v0.0.12-beta Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecMiddlewareChain

func ExecMiddlewareChain(f sockets.HandlerFunc, m []sockets.MiddlewareFunc) sockets.HandlerFunc

ExecMiddlewareChain builds the global middleware chain recursively, functions are first class.

func Logger

func Logger(cfg *LoggerConfig) sockets.MiddlewareFunc

Logger will log the entire received message.

func Metrics

func Metrics() sockets.MiddlewareFunc

Metrics contains basic example metrics that can be captured and pulled into prometheus.

You would most likely implement your own version of this.

func PanicHandler

func PanicHandler(next sockets.HandlerFunc) sockets.HandlerFunc

PanicHandler will handle panics and log the error allowing the service to recover.

func Timeout

func Timeout(cfg *TimeoutConfig) sockets.MiddlewareFunc

Timeout can be used to set a timeout on requests sent to listeners.

Types

type LoggerConfig

type LoggerConfig struct {
	Skipper func(msg *sockets.Message) bool
}

LoggerConfig holds configuration for a middleware based logger. This is used to output detail of the messages received.

func NewLoggerConfig

func NewLoggerConfig() *LoggerConfig

NewLoggerConfig will setup a new LoggerConfig with a default skipper.

func (*LoggerConfig) AddSkipper

func (l *LoggerConfig) AddSkipper(fn func(msg *sockets.Message) bool)

AddSkipper will add a custom skipper function to the logger, you may want to skip some messages but not all, perhaps by message key or only logging every n events.

type TimeoutConfig

type TimeoutConfig struct {
	// Skipper, if true will skip setting timeouts for the request.
	Skipper func(msg *sockets.Message) bool
	Timeout time.Duration
}

TimeoutConfig contains configuration settings for timeing out requests sent to listeners.

func NewTimeoutConfig

func NewTimeoutConfig() *TimeoutConfig

NewTimeoutConfig will setup a new timeout config with default values. This sets the skipper to always return false (don't skip any requests) and the default timeout of 30 seconds.

Jump to

Keyboard shortcuts

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