|
@@ -119,14 +119,14 @@ func (group *RouterGroup) StaticFile(relativePath, filepath string) {
|
|
|
// use :
|
|
// use :
|
|
|
// router.Static("/static", "/var/www")
|
|
// router.Static("/static", "/var/www")
|
|
|
func (group *RouterGroup) Static(relativePath, root string) {
|
|
func (group *RouterGroup) Static(relativePath, root string) {
|
|
|
- group.StaticFS(relativePath, http.Dir(root), false)
|
|
|
|
|
|
|
+ group.StaticFS(relativePath, Dir(root, false))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem, listDirectory bool) {
|
|
|
|
|
|
|
+func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) {
|
|
|
if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") {
|
|
if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") {
|
|
|
panic("URL parameters can not be used when serving a static folder")
|
|
panic("URL parameters can not be used when serving a static folder")
|
|
|
}
|
|
}
|
|
|
- handler := group.createStaticHandler(relativePath, fs, listDirectory)
|
|
|
|
|
|
|
+ handler := group.createStaticHandler(relativePath, fs)
|
|
|
relativePath = path.Join(relativePath, "/*filepath")
|
|
relativePath = path.Join(relativePath, "/*filepath")
|
|
|
|
|
|
|
|
// Register GET and HEAD handlers
|
|
// Register GET and HEAD handlers
|
|
@@ -134,16 +134,10 @@ func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem, list
|
|
|
group.HEAD(relativePath, handler)
|
|
group.HEAD(relativePath, handler)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem, listDirectory bool) HandlerFunc {
|
|
|
|
|
|
|
+func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
|
|
absolutePath := group.calculateAbsolutePath(relativePath)
|
|
absolutePath := group.calculateAbsolutePath(relativePath)
|
|
|
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
|
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
|
|
- return func(c *Context) {
|
|
|
|
|
- if !listDirectory && lastChar(c.Request.URL.Path) == '/' {
|
|
|
|
|
- http.NotFound(c.Writer, c.Request)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- fileServer.ServeHTTP(c.Writer, c.Request)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return WrapH(fileServer)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (group *RouterGroup) combineHandlers(handlers HandlersChain) HandlersChain {
|
|
func (group *RouterGroup) combineHandlers(handlers HandlersChain) HandlersChain {
|