@marcel91200 / caddy Mirror · read-only / commits / 93c99f67
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 20:30 UTC

map: Support numeric and bool types with Caddyfile

Based on caddyserver/website#221

Matthew Holt committed Mar 17, 2022 at 17:53 UTC 93c99f67342504efe9f6b58a734aaec3929fe785
1 file changed +15 -1
modules/caddyhttp/map/caddyfile.go
+15 -1
@@ -15,6 +15,7 @@
15 package maphandler
16
17 import (
18 + "strconv"
19 "strings"
20
21 "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
@@ -78,7 +79,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
79 if out == "-" {
80 outs = append(outs, nil)
81 } else {
81 - outs = append(outs, out)
82 + outs = append(outs, specificType(out))
83 }
84 }
85
@@ -107,3 +108,16 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
108
109 return handler, nil
110 }
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 +}