forked from Fuyu/router
Export NewContext
This commit is contained in:
parent
d504c9d2b5
commit
5b5a102c71
@ -20,7 +20,8 @@ type Context struct {
|
||||
store map[string]interface{}
|
||||
}
|
||||
|
||||
func newContext(router *Router, res http.ResponseWriter, req *http.Request, param httprouter.Params) *Context {
|
||||
// NewContext creates a new context, this function is only exported for use in tests
|
||||
func NewContext(router *Router, res http.ResponseWriter, req *http.Request, param httprouter.Params) *Context {
|
||||
return &Context{router, req, res, param.ByName, make(map[string]interface{})}
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ func (r *Router) getHttpr() *httprouter.Router {
|
||||
})
|
||||
|
||||
httpr.PanicHandler = func(res http.ResponseWriter, req *http.Request, err interface{}) {
|
||||
c := newContext(r, res, req, nil)
|
||||
c := NewContext(r, res, req, nil)
|
||||
r.ErrorHandler(c, err)
|
||||
}
|
||||
|
||||
@ -181,8 +181,6 @@ func checkInterfaceHandle(f interface{}) {
|
||||
if rt.In(0) != reflect.TypeOf(&Context{}) {
|
||||
panic(`handle should accept Context as first argument`)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func handlePOST(r *Router, f interface{}) Handle {
|
||||
@ -213,7 +211,7 @@ func handlePOST(r *Router, f interface{}) Handle {
|
||||
|
||||
func handleReq(r *Router, handle Handle, m []Middleware) httprouter.Handle {
|
||||
return func(res http.ResponseWriter, req *http.Request, param httprouter.Params) {
|
||||
c := newContext(r, res, req, param)
|
||||
c := NewContext(r, res, req, param)
|
||||
|
||||
f := handle
|
||||
for i := len(m) - 1; i >= 0; i-- {
|
||||
|
Loading…
Reference in New Issue
Block a user