middleware

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware interface {
	// Method returns the middleware function that wraps a bmux.HandlerFunc.
	// The function signature is: func(bmux.HandlerFunc) bmux.HandlerFunc
	Method() func(handler.HandlerFunc) handler.HandlerFunc

	// Status returns true if the middleware is enabled, false otherwise.
	Status() bool

	// Experimental returns true if the middleware is experimental or unstable.
	Experimental() bool

	// Name returns the unique name of the middleware.
	Name() string
}

Middleware defines the interface for TCP middleware that wraps bmux.HandlerFunc and provides metadata about the middleware such as name, status, and experimental flag.

This interface enables middleware management, dynamic enabling/disabling, and identification.

func NewMiddleware

func NewMiddleware(
	method func(handler.HandlerFunc) handler.HandlerFunc,
	name string,
	status bool,
	experimental bool,
	opts ...MiddlewareWrapper,
) Middleware

NewMiddleware constructs a new Middleware instance with the provided middleware function, name, enabled status, and experimental flag. Additional MiddlewareWrapper options can be passed to decorate or modify the middleware before returning.

Example:

authMiddleware := NewMiddleware(AuthFunc, "Auth", true, false)
loggingMiddleware := NewMiddleware(LoggingFunc, "Logging", true, false,
  WithLoggingDecorator)

Parameters:

  • method: the TCP middleware handler function.
  • name: a descriptive name for the middleware.
  • status: whether the middleware should be enabled.
  • experimental: whether the middleware is experimental.
  • opts: zero or more MiddlewareWrapper functions to wrap/modify the middleware.

Returns:

A Middleware interface implementation.

type MiddlewareWrapper

type MiddlewareWrapper func(m Middleware) Middleware

MiddlewareWrapper is a function type that accepts and returns a Middleware. It is used to wrap or decorate a Middleware with additional functionality during initialization.

Example usage:

func WithLogging(next Middleware) Middleware {
    return NewMiddleware(func(h bmux.HandlerFunc) bmux.HandlerFunc {
        // wrap handler with logging logic here
    }, next.Name(), next.Status(), next.Experimental())
}

Jump to

Keyboard shortcuts

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