router

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMiddleware

func ConvertMiddleware(ware Middleware) func(Handler) Handler

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

func NewChain

func NewChain(constructors ...Constructor) Chain

func (Chain) Append

func (c Chain) Append(constructors ...Constructor) Chain

func (Chain) Extend

func (c Chain) Extend(chain Chain) Chain

func (Chain) Then

func (c Chain) Then(h Handler) Handler

func (Chain) ThenFunc

func (c Chain) ThenFunc(fn HandlerFunc) Handler

type Constructor

type Constructor func(Handler) Handler

type Handler

type Handler interface {
	Handle(c *conn.Connection, pkg packet.IPacket)
}

func NotFoundHandler

func NotFoundHandler(next Handler) Handler

type HandlerFunc

type HandlerFunc func(conn *conn.Connection, pkg packet.IPacket)

HandlerFunc 消息处理方法

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(c *conn.Connection, pkg packet.IPacket)

type Middleware

type Middleware func(next HandlerFunc) HandlerFunc

func ToMiddleware

func ToMiddleware(handler func(next Handler) Handler) Middleware

ToMiddleware converts the given handler to a Middleware.

type Route

type Route struct {
	Matches any         // 用于匹配的关键字段
	Handler HandlerFunc // 处理方法
}

func WithMiddleware

func WithMiddleware(middleware Middleware, rs ...Route) []Route

WithMiddleware adds given middleware to given route.

func WithMiddlewares

func WithMiddlewares(ms []Middleware, rs ...Route) []Route

WithMiddlewares adds given middlewares to given routes.

type Router

type Router interface {
	Handler
	Register(matches any, handler Handler) error
	SetNotFoundHandler(handler Handler)
}

func NewDefaultRouter

func NewDefaultRouter() Router

Jump to

Keyboard shortcuts

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