Fixes new NoRoute() logic

This commit is contained in:
Manu Mtz-Almeida 2014-07-18 00:29:44 +02:00
parent c7fdc2e03a
commit d0fb4a6bf0

13
gin.go
View File

@ -37,13 +37,14 @@ type (
*RouterGroup
HTMLRender render.Render
cache sync.Pool
handlers404 []HandlerFunc
finalNoRoute []HandlerFunc
noRoute []HandlerFunc
router *httprouter.Router
}
)
func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) {
c := engine.createContext(w, req, nil, engine.handlers404)
c := engine.createContext(w, req, nil, engine.finalNoRoute)
c.Writer.setStatus(404)
c.Next()
if !c.Writer.Written() {
@ -92,7 +93,13 @@ func (engine *Engine) SetHTMLTemplate(templ *template.Template) {
// Adds handlers for NoRoute. It return a 404 code by default.
func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
engine.handlers404 = engine.combineHandlers(handlers)
engine.noRoute = handlers
engine.finalNoRoute = engine.combineHandlers(engine.noRoute)
}
func (engine *Engine) Use(middlewares ...HandlerFunc) {
engine.RouterGroup.Use(middlewares...)
engine.finalNoRoute = engine.combineHandlers(engine.noRoute)
}
// ServeHTTP makes the router implement the http.Handler interface.