filebrowser/filemanager.go

33 lines
934 B
Go
Raw Normal View History

// Package filemanager provides middleware for managing files in a directory
// when directory path is requested instead of a specific file. Based on browse
// middleware.
2016-06-10 13:36:43 +00:00
package filemanager
import (
"net/http"
"github.com/hacdias/filemanager"
2016-06-10 13:36:43 +00:00
"github.com/mholt/caddy/caddyhttp/httpserver"
)
// FileManager is an http.Handler that can show a file listing when
// directories in the given paths are specified.
2016-06-10 13:36:43 +00:00
type FileManager struct {
2016-06-11 20:20:47 +00:00
Next httpserver.Handler
Configs []*filemanager.FileManager
}
2016-11-01 13:46:28 +00:00
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
for i := range f.Configs {
2016-10-18 21:00:26 +00:00
// Checks if this Path should be handled by File Manager.
if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
continue
2016-10-18 21:00:26 +00:00
}
return f.Configs[i].ServeHTTP(w, r)
}
2016-06-11 20:20:47 +00:00
2016-06-10 19:54:19 +00:00
return f.Next.ServeHTTP(w, r)
}