Skip to content

Commit 93c99f6

Browse files
committed
map: Support numeric and bool types with Caddyfile
Based on caddyserver/website#221
1 parent 4e9fbee commit 93c99f6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

modules/caddyhttp/map/caddyfile.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package maphandler
1616

1717
import (
18+
"strconv"
1819
"strings"
1920

2021
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
@@ -78,7 +79,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
7879
if out == "-" {
7980
outs = append(outs, nil)
8081
} else {
81-
outs = append(outs, out)
82+
outs = append(outs, specificType(out))
8283
}
8384
}
8485

@@ -107,3 +108,16 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
107108

108109
return handler, nil
109110
}
111+
112+
func specificType(v string) interface{} {
113+
if num, err := strconv.Atoi(v); err == nil {
114+
return num
115+
}
116+
if num, err := strconv.ParseFloat(v, 64); err == nil {
117+
return num
118+
}
119+
if bool, err := strconv.ParseBool(v); err == nil {
120+
return bool
121+
}
122+
return v
123+
}

0 commit comments

Comments
 (0)