Documentation ¶
Overview ¶
Package tree 提供了以树形结构保存路由项的相关操作
Index ¶
- Variables
- func ApplyMiddleware[T any](h T, f ...types.MiddlewareOf[T]) T
- func BuildTestMiddleware(a *assert.Assertion, text string) types.MiddlewareOf[http.Handler]
- func BuildTestNodeHandlerFunc(status int) types.BuildNodeHandleOf[http.Handler]
- type Tree
- func (tree *Tree[T]) Add(pattern string, h T, methods ...string) error
- func (tree *Tree[T]) ApplyMiddleware(ms ...types.MiddlewareOf[T])
- func (tree *Tree[T]) Clean(prefix string)
- func (tree *Tree[T]) Find(pattern string) *node[T]
- func (tree *Tree[T]) Handler(p *types.Context, method string) (types.Node, T, bool)
- func (tree *Tree[T]) Print(w io.Writer)
- func (tree *Tree[T]) Remove(pattern string, methods ...string)
- func (tree *Tree[T]) Routes() map[string][]string
- func (tree *Tree[T]) 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.MethodHead, http.MethodOptions, } )
Functions ¶
func ApplyMiddleware ¶
func ApplyMiddleware[T any](h T, f ...types.MiddlewareOf[T]) T
func BuildTestMiddleware ¶
func BuildTestMiddleware(a *assert.Assertion, text string) types.MiddlewareOf[http.Handler]
func BuildTestNodeHandlerFunc ¶
func BuildTestNodeHandlerFunc(status int) types.BuildNodeHandleOf[http.Handler]
Types ¶
type Tree ¶
type Tree[T any] 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 New ¶
func New[T any](lock bool, i *syntax.Interceptors, notFound T, methodNotAllowedBuilder, optionsBuilder types.BuildNodeHandleOf[T]) *Tree[T]
func NewTestTree ¶
NewTestTree 返回以 http.Handler 作为参数实例化的 Tree
func (*Tree[T]) ApplyMiddleware ¶
func (tree *Tree[T]) ApplyMiddleware(ms ...types.MiddlewareOf[T])
func (*Tree[T]) Handler ¶
Handler 查找与参数匹配的处理对象
如果未找到,也会返回相应在的处理对象,比如 tree.notFound 或是相应的 methodNotAllowed 方法。
Click to show internal directories.
Click to hide internal directories.