router: handling file not found in StaticFS() to use Router's NoRoute handlers

This commit is contained in:
Oky Antoro 2018-01-03 17:47:28 +07:00
parent a712f77d7a
commit 4983f1b3cf

View File

@ -186,6 +186,18 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
if nolisting {
c.Writer.WriteHeader(404)
}
file := c.Param("filepath")
// Check existence of file
if _, err := fs.Open(file); err != nil {
c.handlers = group.engine.allNoRoute
// Since we change our handler to Router's NotFound,
// we need to reset the index
c.index = -1
serveError(c, 404, default404Body)
return
}
fileServer.ServeHTTP(c.Writer, c.Request)
}
}