-
Notifications
You must be signed in to change notification settings - Fork 6
/
caddyfile.go
77 lines (63 loc) · 1.64 KB
/
caddyfile.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
68
69
70
71
72
73
74
75
76
77
package caddy_geoip
import (
"strconv"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
func (m *GeoIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
d.NextArg()
for d.NextBlock(0) {
var err error
switch d.Val() {
case "db_path":
if !d.Args(&m.DbPath) {
return d.Errf("Missing db path")
}
case "trust_header":
d.Args(&m.TrustHeader)
case "account_id":
var val string
if d.Args(&val) {
accountID, err := strconv.Atoi(val)
if err != nil {
return d.Errf("invalid account number %s: %v", d.Val(), err)
}
m.AccountID = accountID
}
case "api_key":
d.Args(&m.APIKey)
case "reload_frequency":
if !d.NextArg() {
return d.ArgErr()
}
dur, err := caddy.ParseDuration(d.Val())
if err != nil {
return d.Errf("bad duration value %s: %v", d.Val(), err)
}
m.ReloadFrequency = caddy.Duration(dur)
case "download_frequency":
if !d.NextArg() {
return d.ArgErr()
}
dur, err := caddy.ParseDuration(d.Val())
if err != nil {
return d.Errf("bad duration value %s: %v", d.Val(), err)
}
m.DownloadFrequency = caddy.Duration(dur)
case "override_country_code":
d.Args(&m.OverrideCountryCode)
}
if err != nil {
return d.Errf("Error parsing %s: %s", d.Val(), err)
}
}
return nil
}
// parseCaddyfile unmarshal tokens from h into a new Middleware.
func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
var m GeoIP
err := m.UnmarshalCaddyfile(h.Dispenser)
return &m, err
}