Documentation ¶
Overview ¶
Package tree 提供了以树形结构保存路由项的相关操作
Index ¶
- Variables
- type HandlerFunc
- type Node
- type Tree
- func (tree *Tree) Add(pattern string, h HandlerFunc, methods ...string) error
- func (tree *Tree) Clean(prefix string)
- func (tree *Tree) Print(w io.Writer)
- func (tree *Tree) Remove(pattern string, methods ...string)
- func (tree *Tree) Route(path string) (*Node, *syntax.Params)
- func (tree *Tree) Routes() map[string][]string
- func (tree *Tree) URL(buf *errwrap.StringBuilder, pattern string, ps map[string]string) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Methods 所有支持请求方法 Methods = []string{ http.MethodGet, http.MethodPost, http.MethodDelete, http.MethodPut, http.MethodPatch, http.MethodConnect, http.MethodTrace, http.MethodOptions, http.MethodHead, } )
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
HandlerFunc 路由处理的函数类型
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree 以树节点的形式保存的路由
多段路由项,会提取其中的相同的内容组成树状结构的节点。 比如以下路由项:
/posts/{id}/author /posts/{id}/author/emails /posts/{id}/author/profile /posts/1/author
会被转换成以下结构
/posts | +---- 1/author | +---- {id}/author | +---- /profile | +---- /emails
func (*Tree) Add ¶
func (tree *Tree) Add(pattern string, h HandlerFunc, methods ...string) error
Add 添加路由项
methods 可以为空,表示添加除 OPTIONS 和 HEAD 之外所有支持的请求方法。
Click to show internal directories.
Click to hide internal directories.