diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2022-03-17 17:53:32 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2022-03-17 17:53:32 -0600 |
commit | 93c99f67342504efe9f6b58a734aaec3929fe785 (patch) | |
tree | 8c3c4df874a62e0f596c8bfdb3bc0af93020c39e /modules | |
parent | 4e9fbee1e2ef39ff56bdfb19126a9b1a8a841eb4 (diff) |
map: Support numeric and bool types with Caddyfile
Based on caddyserver/website#221
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/map/caddyfile.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/caddyhttp/map/caddyfile.go b/modules/caddyhttp/map/caddyfile.go index 77d4c46..a7f809b 100644 --- a/modules/caddyhttp/map/caddyfile.go +++ b/modules/caddyhttp/map/caddyfile.go @@ -15,6 +15,7 @@ package maphandler import ( + "strconv" "strings" "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile" @@ -78,7 +79,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) if out == "-" { outs = append(outs, nil) } else { - outs = append(outs, out) + outs = append(outs, specificType(out)) } } @@ -107,3 +108,16 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) return handler, nil } + +func specificType(v string) interface{} { + if num, err := strconv.Atoi(v); err == nil { + return num + } + if num, err := strconv.ParseFloat(v, 64); err == nil { + return num + } + if bool, err := strconv.ParseBool(v); err == nil { + return bool + } + return v +} |