From 9a6c03a9e5306d76020d2b7aa6ac38ac9e3cc01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giovanny=20Guti=C3=A9rrez?= Date: Fri, 13 Aug 2021 20:50:26 -0500 Subject: [PATCH] fix(config): Support colon as default value in config.yaml (#1332) --- config/config_test.go | 6 ++++++ config/options.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config_test.go b/config/config_test.go index 7bdacd8b7..e18bb685b 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -183,6 +183,7 @@ func TestDefaultResolver(t *testing.T) { "enable": "${ENABLE:false}", "rate": "${RATE}", "empty": "${EMPTY:foobar}", + "url": "${URL:http://example.com}", "array": []interface{}{ "${PORT}", map[string]interface{}{"foobar": "${NOTEXIST:8081}"}, @@ -237,6 +238,11 @@ func TestDefaultResolver(t *testing.T) { path: "foo.bar.empty", expect: "", }, + { + name: "test url with default", + path: "foo.bar.url", + expect: "http://example.com", + }, { name: "test array", path: "foo.bar.array", diff --git a/config/options.go b/config/options.go index 3574e9744..a96d8939e 100644 --- a/config/options.go +++ b/config/options.go @@ -84,7 +84,7 @@ func defaultDecoder(src *KeyValue, target map[string]interface{}) error { // placeholder format in ${key:default} or $key. func defaultResolver(input map[string]interface{}) error { mapper := func(name string) string { - args := strings.Split(strings.TrimSpace(name), ":") + args := strings.SplitN(strings.TrimSpace(name), ":", 2) if v, has := readValue(input, args[0]); has { s, _ := v.String() return s