2 Star 1 Fork 0

法马智慧/fmgo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
node.go 685 Bytes
一键复制 编辑 原始数据 按行查看 历史
零海 提交于 2022-11-17 16:51 . 重构emqx日志
package emqx
type node struct {
*Options
children map[string]*node
Handler HandlerFunc
}
// addRoute adds a route to the tree
func (n *node) addRoute(urlList []string, handler HandlerFunc) *node {
if len(urlList) == 0 {
n.Handler = handler
return n
}
if n.children == nil {
n.children = make(map[string]*node)
}
child := node{}
n.children[urlList[0]] = child.addRoute(urlList[1:], handler)
return n
}
// FindRoute finds a route in the tree
func (n *node) FindRoute(url []string) *node {
if len(url) == 0 {
return n
}
if n.children == nil {
return nil
}
child := n.children[url[0]]
if child == nil {
return nil
}
return child.FindRoute(url[1:])
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fmpt/fmgo.git
git@gitee.com:fmpt/fmgo.git
fmpt
fmgo
fmgo
v1.2.45

搜索帮助

A270a887 8829481 3d7a4017 8829481