forked from filebrowser/filebrowser
/
get.go
44 lines (37 loc) · 983 Bytes
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package browse
import (
"net/http"
"text/template"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/utils"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/browse"
)
// GET handles the GET method on browse page and shows the files listing Using
// the Browse Caddy middleware.
func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
functions := template.FuncMap{
"CanBeEdited": utils.CanBeEdited,
"Defined": utils.Defined,
}
tpl, err := utils.GetTemplate(r, functions, "browse")
if err != nil {
return http.StatusInternalServerError, err
}
// Using Caddy's Browse middleware
b := browse.Browse{
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
return 404, nil
}),
Root: c.Path,
Configs: []browse.Config{
{
PathScope: "/",
Variables: c,
Template: tpl,
},
},
IgnoreIndexes: true,
}
return b.ServeHTTP(w, r)
}