From 60b00c8ade032c18b1bba9c9a96a84db4a574bae Mon Sep 17 00:00:00 2001 From: icylight <408209435@qq.com> Date: Wed, 31 Aug 2022 22:58:32 +0800 Subject: [PATCH] fix(config/env): prefixs typo (#2321) --- config/env/env.go | 10 +++++----- config/env/env_test.go | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/config/env/env.go b/config/env/env.go index 6c104f1c1..30e011b92 100644 --- a/config/env/env.go +++ b/config/env/env.go @@ -8,11 +8,11 @@ import ( ) type env struct { - prefixs []string + prefixes []string } -func NewSource(prefixs ...string) config.Source { - return &env{prefixs: prefixs} +func NewSource(prefixes ...string) config.Source { + return &env{prefixes: prefixes} } func (e *env) Load() (kv []*config.KeyValue, err error) { @@ -29,8 +29,8 @@ func (e *env) load(envStrings []string) []*config.KeyValue { v = subs[1] } - if len(e.prefixs) > 0 { - p, ok := matchPrefix(e.prefixs, k) + if len(e.prefixes) > 0 { + p, ok := matchPrefix(e.prefixes, k) if !ok || len(p) == len(k) { continue } diff --git a/config/env/env_test.go b/config/env/env_test.go index 6574c1d83..72fcff31d 100644 --- a/config/env/env_test.go +++ b/config/env/env_test.go @@ -261,7 +261,7 @@ func TestEnvWithoutPrefix(t *testing.T) { func Test_env_load(t *testing.T) { type fields struct { - prefixs []string + prefixes []string } type args struct { envStrings []string @@ -275,7 +275,7 @@ func Test_env_load(t *testing.T) { { name: "without prefixes", fields: fields{ - prefixs: nil, + prefixes: nil, }, args: args{ envStrings: []string{ @@ -294,7 +294,7 @@ func Test_env_load(t *testing.T) { { name: "empty prefix", fields: fields{ - prefixs: []string{""}, + prefixes: []string{""}, }, args: args{ envStrings: []string{ @@ -313,7 +313,7 @@ func Test_env_load(t *testing.T) { { name: "underscore prefix", fields: fields{ - prefixs: []string{"_"}, + prefixes: []string{"_"}, }, args: args{ envStrings: []string{ @@ -332,7 +332,7 @@ func Test_env_load(t *testing.T) { { name: "with prefixes", fields: fields{ - prefixs: []string{"KRATOS_", "FOO"}, + prefixes: []string{"KRATOS_", "FOO"}, }, args: args{ envStrings: []string{ @@ -351,7 +351,7 @@ func Test_env_load(t *testing.T) { { name: "should not panic #1", fields: fields{ - prefixs: []string{"FOO"}, + prefixes: []string{"FOO"}, }, args: args{ envStrings: []string{ @@ -364,7 +364,7 @@ func Test_env_load(t *testing.T) { { name: "should not panic #2", fields: fields{ - prefixs: []string{"FOO=1"}, + prefixes: []string{"FOO=1"}, }, args: args{ envStrings: []string{ @@ -377,7 +377,7 @@ func Test_env_load(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { e := &env{ - prefixs: tt.fields.prefixs, + prefixes: tt.fields.prefixes, } got := e.load(tt.args.envStrings) if !reflect.DeepEqual(tt.want, got) { @@ -419,8 +419,8 @@ func Test_matchPrefix(t *testing.T) { } func Test_env_watch(t *testing.T) { - prefixs := []string{"BAR", "FOO"} - source := NewSource(prefixs...) + prefixes := []string{"BAR", "FOO"} + source := NewSource(prefixes...) w, err := source.Watch() if err != nil { t.Errorf("expect no err, got %v", err)