Context
context内部包含了*http.Request和http.ResponseWriter
type Context struct {
// 对内使用,可以用于接受http.ResponseWriter的值
writermem responseWriter
Request *http.Request
// http.ResponseWriter的增强版
Writer ResponseWriter
Params Params
handlers HandlersChain
index int8
fullPath string
engine *Engine
// This mutex protect Keys map
mu sync.RWMutex
// Keys is a key/value pair exclusively for the context of each request.
Keys map[string]interface{}
// Errors is a list of errors attached to all the handlers/middlewares who used this context.
Errors errorMsgs
//...
}
路由
路由分组是基于Radix树,即基数树,也称压缩前缀树
r.GET("/user/:id", test)
r.GET("/user/:id/page", test) // ok
r.GET("/user/name", test) // panic