-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unmarshaller.go
51 lines (40 loc) · 915 Bytes
/
unmarshaller.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
package teler
import "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
var cfgFormat, cfgPath, cfgInline string
if !d.Next() { // consume directive name
return d.Errf(errExpectedToken, dir)
}
for d.NextBlock(0) {
key := d.Val()
var target *string
switch key {
case keyLoadFrom:
target = &cfgPath
case keyInline:
target = &cfgInline
default:
return d.Errf(errInvalidKey, key)
}
if !d.Args(&cfgFormat, target) {
return d.ArgErr()
}
format, err := validateCfgFormat(cfgFormat, key)
if err != nil {
return d.WrapErr(err)
}
if d.NextArg() {
// too many args
return d.ArgErr()
}
m.Format = format
switch key {
case keyLoadFrom:
m.LoadFrom = cfgPath
case keyInline:
m.Inline = cfgInline
}
}
return nil
}