router

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context          // embeds standard context.Context
	Conn            net.Conn // TCP connection
	Header          any      // parsed header object
	Body            []byte   // message body
}

type HandlerFunc

type HandlerFunc func(*Context)

type Route

type Route interface {
	// ID returns the int32 message ID this route handles.
	ID() int32

	// Name returns the name of the route, useful for logging.
	Name() string

	// Handler returns the bmux.HandlerFunc for this message.
	Handler() HandlerFunc

	// Status indicates whether the route is enabled.
	Status() bool

	// Experimental indicates if the route is experimental.
	Experimental() bool

	// Middleware returns middleware applied only to this route.
	Middleware() []func(HandlerFunc) HandlerFunc
}

Route defines a handler for a specific message ID in the bmux protocol.

func NewRoute

func NewRoute(
	name string,
	id int32,
	status, experimental bool,
	handler HandlerFunc,
	middleware []func(HandlerFunc) HandlerFunc,
	opts ...RouteWrapper,
) Route

type RouteWrapper

type RouteWrapper func(r Route) Route

type Router

type Router interface {
	// Routes returns all registered routes in the router.
	Routes() []Route

	// Status indicates whether this router is currently active.
	Status() bool

	// Middleware returns router-level middleware applied to all routes.
	// Middleware wraps the handler with additional behavior.
	Middleware() []func(HandlerFunc) HandlerFunc
}

Router defines a message-based router for the bmux protocol. It maps incoming message identifiers (int32) to handlers, supports middleware, and allows for enabling/disabling routers.

func NewRouter

func NewRouter(
	status bool,
	routes []Route,
	middleware []func(HandlerFunc) HandlerFunc,
	opts ...RouterWrapper,
) Router

type RouterWrapper

type RouterWrapper func(r Router) Router

Jump to

Keyboard shortcuts

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