filebrowser/routes/browse/get.go

45 lines
1006 B
Go
Raw Normal View History

2015-09-26 21:02:49 +00:00
package browse
import (
"net/http"
"text/template"
2016-03-06 19:18:46 +00:00
"github.com/hacdias/caddy-hugo/tools/templates"
2016-03-06 20:37:49 +00:00
"github.com/hacdias/caddy-hugo/tools/variables"
2015-09-26 21:02:49 +00:00
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/browse"
)
2016-02-14 10:20:47 +00:00
// GET handles the GET method on browse page and shows the files listing Using
// the Browse Caddy middleware.
2016-03-12 09:52:04 +00:00
func GET(w http.ResponseWriter, r *http.Request) (int, error) {
2015-09-26 21:02:49 +00:00
functions := template.FuncMap{
2016-03-06 19:18:46 +00:00
"CanBeEdited": templates.CanBeEdited,
2016-03-06 20:37:49 +00:00
"Defined": variables.Defined,
2015-09-26 21:02:49 +00:00
}
2016-03-06 19:18:46 +00:00
tpl, err := templates.Get(r, functions, "browse")
2015-09-26 21:02:49 +00:00
if err != nil {
2015-09-26 21:19:22 +00:00
return http.StatusInternalServerError, err
2015-09-26 21:02:49 +00:00
}
2016-02-07 15:14:56 +00:00
// Using Caddy's Browse middleware
2015-09-26 21:02:49 +00:00
b := browse.Browse{
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
return 404, nil
}),
Configs: []browse.Config{
{
PathScope: "/",
2016-04-26 19:21:07 +00:00
Root: http.Dir(conf.Path),
2016-03-12 09:52:04 +00:00
Variables: conf,
2015-09-26 21:02:49 +00:00
Template: tpl,
},
},
IgnoreIndexes: true,
}
return b.ServeHTTP(w, r)
}