Skip to content

Commit

Permalink
logging: Implement Caddyfile support for ip_mask
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Sep 2, 2020
1 parent 374d229 commit ccdb262
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion modules/logging/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,35 @@ func (IPMaskFilter) CaddyModule() caddy.ModuleInfo {
}

// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
func (IPMaskFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
func (m *IPMaskFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
for d.NextBlock(0) {
switch d.Val() {
case "ipv4":
if !d.NextArg() {
return d.ArgErr()
}
if _, err := strconv.Atoi(d.Val()); err == nil {
m.IPv4MaskRaw = json.RawMessage(d.Val())
} else {
m.IPv4MaskRaw = json.RawMessage(`"` + d.Val() + `"`)
}

case "ipv6":
if !d.NextArg() {
return d.ArgErr()
}
if _, err := strconv.Atoi(d.Val()); err == nil {
m.IPv6MaskRaw = json.RawMessage(d.Val())
} else {
m.IPv6MaskRaw = json.RawMessage(`"` + d.Val() + `"`)
}

default:
return d.Errf("unrecognized subdirective %s", d.Val())
}
}
}
return nil
}

Expand Down

0 comments on commit ccdb262

Please sign in to comment.