tree

package
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package tree 提供了以树形结构保存路由项的相关操作。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 New

func New(disableOptions, disableHead bool) *Tree

New 声明一个 Tree 实例

func (*Tree) Add

func (tree *Tree) Add(pattern string, h http.Handler, methods ...string) error

Add 添加路由项

methods 可以为空,表示添加除 OPTIONS 之外所有支持的请求方法。

func (*Tree) All added in v2.2.0

func (tree *Tree) All(ignoreHead, ignoreOptions bool) map[string][]string

All 获取当前的所有路径项

func (*Tree) Clean

func (tree *Tree) Clean(prefix string)

Clean 清除路由项

func (*Tree) Handler

func (tree *Tree) Handler(path string) (*handlers.Handlers, params.Params)

Handler 找到与当前内容匹配的 handlers.Handlers 实例

func (*Tree) Print

func (tree *Tree) Print(w io.Writer)

Print 向 w 输出树状结构

func (*Tree) Remove

func (tree *Tree) Remove(pattern string, methods ...string)

Remove 移除路由项

methods 可以为空,表示删除所有内容。

func (*Tree) SetAllow

func (tree *Tree) SetAllow(pattern, allow string)

SetAllow 设置指定节点的 allow 报头

若节点不存在,则会自动生成该节点。

func (*Tree) Trace

func (tree *Tree) Trace(w io.Writer, path string)

Trace 向 w 输出详细的节点匹配过程

func (*Tree) URL

func (tree *Tree) URL(pattern string, params map[string]string) (string, error)

URL 根据参数生成地址

若节点不存在,则会自动生成。

Jump to

Keyboard shortcuts

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