Documentation ¶
Index ¶
- type Multistage
- func (slf *Multistage[HandleFunc]) Match(routes ...any) HandleFunc
- func (slf *Multistage[HandleFunc]) Register(routes ...any) MultistageBind[HandleFunc]
- func (slf *Multistage[HandleFunc]) Route(route any, handleFunc HandleFunc)
- func (slf *Multistage[HandleFunc]) Sub(route any) *Multistage[HandleFunc]
- type MultistageBind
- type MultistageOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Multistage ¶ added in v0.1.7
type Multistage[HandleFunc any] struct { // contains filtered or unexported fields }
Multistage 支持多级分类的路由器
func NewMultistage ¶ added in v0.1.7
func NewMultistage[HandleFunc any](options ...MultistageOption[HandleFunc]) *Multistage[HandleFunc]
NewMultistage 创建一个支持多级分类的路由器
Example ¶
package main import ( "github.com/kercylan98/minotaur/server/router" ) func main() { router.NewMultistage[func()]() }
Output:
func (*Multistage[HandleFunc]) Match ¶ added in v0.1.7
func (slf *Multistage[HandleFunc]) Match(routes ...any) HandleFunc
Match 匹配已绑定处理函数的路由,返回处理函数
- 如果未找到将会返回空指针
Example ¶
package main import ( "github.com/kercylan98/minotaur/server/router" ) func main() { r := router.NewMultistage[func()]() r.Route("ServerTime", func() {}) r.Register("System", "Network", "Ping").Bind(func() {}) r.Match("ServerTime")() r.Match("System", "Network", "Ping")() }
Output:
func (*Multistage[HandleFunc]) Register ¶ added in v0.1.7
func (slf *Multistage[HandleFunc]) Register(routes ...any) MultistageBind[HandleFunc]
Register 注册路由是结合 Sub 和 Route 的快捷方式,用于一次性注册多级路由
- 该函数将返回一个注册函数,可通过调用其将路由绑定到特定处理函数,例如:router.Register("a", "b").Bind(onExec())
Example ¶
package main import ( "github.com/kercylan98/minotaur/server/router" ) func main() { r := router.NewMultistage[func()]() r.Register("System", "Network", "Ping")(func() { // ... }) }
Output:
func (*Multistage[HandleFunc]) Route ¶ added in v0.1.7
func (slf *Multistage[HandleFunc]) Route(route any, handleFunc HandleFunc)
Route 为特定路由绑定处理函数,被绑定的处理函数将可以通过 Match 函数进行匹配
Example ¶
package main import ( "github.com/kercylan98/minotaur/server/router" ) func main() { r := router.NewMultistage[func()]() r.Route("ServerTime", func() { // ... }) }
Output:
func (*Multistage[HandleFunc]) Sub ¶ added in v0.1.7
func (slf *Multistage[HandleFunc]) Sub(route any) *Multistage[HandleFunc]
Sub 获取子路由器
Example ¶
package main import ( "github.com/kercylan98/minotaur/server/router" ) func main() { r := router.NewMultistage[func()]() r.Sub("System").Route("Heartbeat", func() { // ... }) }
Output:
type MultistageBind ¶ added in v0.1.7
type MultistageBind[HandleFunc any] func(HandleFunc)
MultistageBind 多级分类路由绑定函数
func (MultistageBind[HandleFunc]) Bind ¶ added in v0.1.7
func (slf MultistageBind[HandleFunc]) Bind(handleFunc HandleFunc)
Bind 将处理函数绑定到预设的路由中
type MultistageOption ¶ added in v0.1.7
type MultistageOption[HandleFunc any] func(multistage *Multistage[HandleFunc])
MultistageOption 路由器选项
func WithRouteTrim ¶ added in v0.1.7
func WithRouteTrim[HandleFunc any](handle func(route any) any) MultistageOption[HandleFunc]
WithRouteTrim 路由修剪选项
- 将在路由注册前对路由进行对应处理
Click to show internal directories.
Click to hide internal directories.