Documentation
¶
Overview ¶
Package gohttprouter 提供路由处理存储
Package gohttprouter 提供简单http路由
Index ¶
- Variables
- type Handler
- type LeafNode
- type Node
- type Options
- type Param
- type Params
- type Router
- func (r *Router) Abort()
- func (r *Router) Cors(opts Options) Handler
- func (r *Router) DELETE(path string, handlers ...Handler)
- func (r *Router) GET(path string, handlers ...Handler)
- func (r *Router) GetData(key string) interface{}
- func (r *Router) Group(prefix string, level int) *Router
- func (r *Router) GroupUse(level int, handlers ...Handler) *Router
- func (r *Router) HEAD(path string, handlers ...Handler)
- func (r *Router) Handle(method, path string, handles []Handler)
- func (r *Router) Handler(method, path string, handler http.Handler)
- func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
- func (r *Router) HandlerNext(w http.ResponseWriter, req *http.Request)
- func (r *Router) OPTIONS(path string, handlers ...Handler)
- func (r *Router) PATCH(path string, handlers ...Handler)
- func (r *Router) POST(path string, handlers ...Handler)
- func (r *Router) PUT(path string, handlers ...Handler)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SetData(key string, value interface{})
- type RouterGroup
- type Son
- type Sons
- type Tree
Constants ¶
This section is empty.
Variables ¶
var AllowAll = Options{
AllowOrigins: "*",
AllowHeaders: "*",
AllowMethods: "*",
}
AllowAll is the option that allows all origins, headers, and methods.
var ParamsKey = paramsKey{}
ParamsKey 参数key
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// the allowed origins (separated by commas). Use an asterisk (*) to indicate allowing all origins, "null" to indicate disallowing any.
AllowOrigins string
// whether the response to request can be exposed when the omit credentials flag is unset, or whether the actual request can include user credentials.
AllowCredentials bool
// the HTTP methods (separated by commas) that can be used during the actual request. Use an asterisk (*) to indicate allowing any method.
AllowMethods string
// the HTTP headers (separated by commas) that can be used during the actual request. Use an asterisk (*) to indicate allowing any header.
AllowHeaders string
// the HTTP headers (separated by commas) that are safe to expose to the API of a CORS API specification
ExposeHeaders string
// Max amount of seconds that the results of a preflight request can be cached in a preflight result cache.
MaxAge time.Duration
// contains filtered or unexported fields
}
Options specifies how the CORS handler should respond with appropriate CORS headers.
type Router ¶
type Router struct {
RouterGroup *RouterGroup
Prefix string
Trees map[string]*Tree
PanicHandler func(http.ResponseWriter, *http.Request)
NotFound http.Handler
PathSlash bool
UseEscapedPath bool
HandleOptions bool
HandleMethodNotAllowed bool
MethodNotAllowed http.Handler
HandlerIndex int
Handlers []Handler
Data map[string]interface{}
}
Router 路由结构体
func (*Router) Cors ¶
Cors Handler creates a routing handler that adds appropriate CORS headers according to the specified options and the request.
func (*Router) Group ¶
Group group分组方法
router.Group("/test1",1)
分组时第一个参数为组的路由前缀,第二个参数为组的层级,比如:第一个分组层级为1,第二个则为2, 第一个分组下面在进行分组,层级为11,12,13以此类推,第二个分组下面在进行分组,层级为21,22,23以此类推,
func (*Router) GroupUse ¶
GroupUse use路由预处理函数
router.Use(1,Print11,Print22)
test1 := router.Group("/test1", 1)
test1.Use(11,Print11)
test1.GET("/index", Index, Print)
第一个参数为路由组层级,与Group类似,可多级关联,执行当前组预处理函数时必须通过其父级预处理函数组
func (*Router) Handler ¶
Handler is an adapter which allows the usage of an http.Handler as a request handle. With go 1.7+, the Params will be available in the request context under ParamsKey.
func (*Router) HandlerFunc ¶
func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
HandlerFunc 内置处理函数
func (*Router) HandlerNext ¶
func (r *Router) HandlerNext(w http.ResponseWriter, req *http.Request)
HandlerNext Next调用与当前路由关联的其余处理程序
type RouterGroup ¶
RouterGroup 路由组
func (*RouterGroup) HandlerGenerate ¶
func (r *RouterGroup) HandlerGenerate(index int) (handlers []Handler)
HandlerGenerate 获取路由组所有指定执行的方法
func (*RouterGroup) HandlerInsert ¶
func (r *RouterGroup) HandlerInsert(index int, handlers ...Handler)
HandlerInsert 加入路由组处理方法
func (*RouterGroup) PrefixGenerate ¶
func (r *RouterGroup) PrefixGenerate(index int) (path string)
PrefixGenerate 生成路由组前缀
func (*RouterGroup) PrefixInsert ¶
func (r *RouterGroup) PrefixInsert(index int, prefix string)
PrefixInsert 加入路由组前缀
