mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-14 06:46:27 +03:00
map: Support numeric and bool types with Caddyfile
Based on caddyserver/website#221
This commit is contained in:
parent
4e9fbee1e2
commit
93c99f6734
1 changed files with 15 additions and 1 deletions
|
@ -15,6 +15,7 @@
|
||||||
package maphandler
|
package maphandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
|
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
|
||||||
|
@ -78,7 +79,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
|
||||||
if out == "-" {
|
if out == "-" {
|
||||||
outs = append(outs, nil)
|
outs = append(outs, nil)
|
||||||
} else {
|
} 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
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue