Export NewContext

This commit is contained in:
Nise Void 2020-04-09 10:41:23 +02:00
parent d504c9d2b5
commit 5b5a102c71
Signed by untrusted user: NiseVoid
GPG Key ID: FBA14AC83EA602F3
2 changed files with 4 additions and 5 deletions

View File

@ -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{})}
}

View File

@ -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-- {