2016-06-10 13:36:43 +00:00
|
|
|
package filemanager
|
|
|
|
|
|
|
|
import (
|
2016-06-28 09:24:02 +00:00
|
|
|
"github.com/hacdias/caddy-filemanager/config"
|
2016-06-10 13:36:43 +00:00
|
|
|
"github.com/mholt/caddy"
|
|
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
caddy.RegisterPlugin("filemanager", caddy.Plugin{
|
|
|
|
ServerType: "http",
|
|
|
|
Action: setup,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-06-11 20:20:47 +00:00
|
|
|
// setup configures a new FileManager middleware instance.
|
2016-06-10 13:36:43 +00:00
|
|
|
func setup(c *caddy.Controller) error {
|
2016-06-25 20:57:10 +00:00
|
|
|
configs, err := config.Parse(c)
|
2016-06-10 17:27:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-10 13:36:43 +00:00
|
|
|
|
2016-06-22 20:30:40 +00:00
|
|
|
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
2016-06-11 20:20:47 +00:00
|
|
|
return FileManager{Configs: configs, Next: next}
|
2016-06-10 17:27:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|