-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.go
48 lines (40 loc) · 848 Bytes
/
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
package restic
import (
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy/caddyhttp/httpserver"
restserver "github.com/restic/rest-server"
)
func init() {
caddy.RegisterPlugin("restic", caddy.Plugin{
ServerType: "http",
Action: setup,
})
}
func setup(c *caddy.Controller) error {
var basePath string
restConfig := restserver.Server{}
for c.Next() {
if c.NextArg() {
basePath = c.Val()
}
if c.NextArg() {
restConfig.Path = c.Val()
}
if c.NextArg() {
return c.ArgErr()
}
}
if basePath == "" {
basePath = "/"
}
httpConfig := httpserver.GetConfig(c)
mid := func(next httpserver.Handler) httpserver.Handler {
return ResticHandler{
Next: next,
BasePath: basePath,
RestServerMux: restserver.NewHandler(restConfig),
}
}
httpConfig.AddMiddleware(mid)
return nil
}