Fixes new NoRoute() logic
This commit is contained in:
parent
c7fdc2e03a
commit
d0fb4a6bf0
13
gin.go
13
gin.go
@ -37,13 +37,14 @@ type (
|
|||||||
*RouterGroup
|
*RouterGroup
|
||||||
HTMLRender render.Render
|
HTMLRender render.Render
|
||||||
cache sync.Pool
|
cache sync.Pool
|
||||||
handlers404 []HandlerFunc
|
finalNoRoute []HandlerFunc
|
||||||
|
noRoute []HandlerFunc
|
||||||
router *httprouter.Router
|
router *httprouter.Router
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) {
|
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.Writer.setStatus(404)
|
||||||
c.Next()
|
c.Next()
|
||||||
if !c.Writer.Written() {
|
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.
|
// Adds handlers for NoRoute. It return a 404 code by default.
|
||||||
func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
|
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.
|
// ServeHTTP makes the router implement the http.Handler interface.
|
||||||
|
Loading…
Reference in New Issue
Block a user