-
Notifications
You must be signed in to change notification settings - Fork 11
/
caddy.go
61 lines (53 loc) · 1.28 KB
/
caddy.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
package caddy2proxyprotocol
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)
func init() {
caddy.RegisterModule(Wrapper{})
}
func (Wrapper) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "caddy.listeners.proxy_protocol",
New: func() caddy.Module { return new(Wrapper) },
}
}
// UnmarshalCaddyfile sets up the listener wrapper from Caddyfile tokens. Syntax:
//
// proxy_protocol {
// timeout <duration>
// allow <IPs...>
// }
//
func (w *Wrapper) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
// No same-line options are supported
if d.NextArg() {
return d.ArgErr()
}
for d.NextBlock(0) {
switch d.Val() {
case "timeout":
if !d.NextArg() {
return d.ArgErr()
}
dur, err := caddy.ParseDuration(d.Val())
if err != nil {
return d.Errf("parsing proxy_protocol timeout duration: %v", err)
}
w.Timeout = caddy.Duration(dur)
case "allow":
w.Allow = append(w.Allow, d.RemainingArgs()...)
default:
return d.ArgErr()
}
}
}
return nil
}
var (
_ caddy.Provisioner = (*Wrapper)(nil)
_ caddy.Module = (*Wrapper)(nil)
_ caddy.ListenerWrapper = (*Wrapper)(nil)
_ caddyfile.Unmarshaler = (*Wrapper)(nil)
)