(relativePath string, fs http.FileSystem)
| 214 | } |
| 215 | |
| 216 | func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc { |
| 217 | absolutePath := group.calculateAbsolutePath(relativePath) |
| 218 | fileServer := http.StripPrefix(absolutePath, http.FileServer(fs)) |
| 219 | |
| 220 | return func(c *Context) { |
| 221 | if _, noListing := fs.(*OnlyFilesFS); noListing { |
| 222 | c.Writer.WriteHeader(http.StatusNotFound) |
| 223 | } |
| 224 | |
| 225 | file := c.Param("filepath") |
| 226 | // Check if file exists and/or if we have permission to access it |
| 227 | f, err := fs.Open(file) |
| 228 | if err != nil { |
| 229 | c.Writer.WriteHeader(http.StatusNotFound) |
| 230 | c.handlers = group.engine.noRoute |
| 231 | // Reset index |
| 232 | c.index = -1 |
| 233 | return |
| 234 | } |
| 235 | f.Close() |
| 236 | |
| 237 | fileServer.ServeHTTP(c.Writer, c.Request) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func (group *RouterGroup) combineHandlers(handlers HandlersChain) HandlersChain { |
| 242 | finalSize := len(group.Handlers) + len(handlers) |
no test coverage detected