-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
67 lines (51 loc) · 1.02 KB
/
setup.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ace
import (
"net/http"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
func init() {
caddy.RegisterPlugin("ace", caddy.Plugin{
ServerType: "http",
Action: setup,
})
}
// setup configures a new ace middleware instance.
func setup(c *caddy.Controller) error {
aceconfigs, err := aceParse(c)
if err != nil {
return err
}
cfg := httpserver.GetConfig(c)
ace := Ace{
Root: cfg.Root,
FileSys: http.Dir(cfg.Root),
Configs: aceconfigs,
IndexFiles: []string{"index.ace"},
}
cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
ace.Next = next
return ace
})
return nil
}
func aceParse(c *caddy.Controller) ([]*Config, error) {
var aceconfigs []*Config
ace := &Config{
Path: "",
Extensions: make(map[string]struct{}),
}
for c.Next() {
args := c.RemainingArgs()
switch len(args) {
case 0:
continue
case 1:
ace.Path = args[0]
default:
continue
}
}
aceconfigs = append(aceconfigs, ace)
return aceconfigs, nil
}