mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
fix(config): Support colon as default value in config.yaml (#1332)
This commit is contained in:
parent
4b6ab21ae5
commit
9a6c03a9e5
@ -183,6 +183,7 @@ func TestDefaultResolver(t *testing.T) {
|
|||||||
"enable": "${ENABLE:false}",
|
"enable": "${ENABLE:false}",
|
||||||
"rate": "${RATE}",
|
"rate": "${RATE}",
|
||||||
"empty": "${EMPTY:foobar}",
|
"empty": "${EMPTY:foobar}",
|
||||||
|
"url": "${URL:http://example.com}",
|
||||||
"array": []interface{}{
|
"array": []interface{}{
|
||||||
"${PORT}",
|
"${PORT}",
|
||||||
map[string]interface{}{"foobar": "${NOTEXIST:8081}"},
|
map[string]interface{}{"foobar": "${NOTEXIST:8081}"},
|
||||||
@ -237,6 +238,11 @@ func TestDefaultResolver(t *testing.T) {
|
|||||||
path: "foo.bar.empty",
|
path: "foo.bar.empty",
|
||||||
expect: "",
|
expect: "",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "test url with default",
|
||||||
|
path: "foo.bar.url",
|
||||||
|
expect: "http://example.com",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "test array",
|
name: "test array",
|
||||||
path: "foo.bar.array",
|
path: "foo.bar.array",
|
||||||
|
@ -84,7 +84,7 @@ func defaultDecoder(src *KeyValue, target map[string]interface{}) error {
|
|||||||
// placeholder format in ${key:default} or $key.
|
// placeholder format in ${key:default} or $key.
|
||||||
func defaultResolver(input map[string]interface{}) error {
|
func defaultResolver(input map[string]interface{}) error {
|
||||||
mapper := func(name string) string {
|
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 {
|
if v, has := readValue(input, args[0]); has {
|
||||||
s, _ := v.String()
|
s, _ := v.String()
|
||||||
return s
|
return s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user