diff --git a/config/default.go b/config/default.go index e8c91b89..59f7d230 100644 --- a/config/default.go +++ b/config/default.go @@ -5,6 +5,8 @@ import ( "reflect" "strconv" "strings" + + rutil "github.com/unistack-org/micro/v3/util/reflect" ) type defaultConfig struct { @@ -45,7 +47,7 @@ func (c *defaultConfig) Load(ctx context.Context) error { } func (c *defaultConfig) fillValue(ctx context.Context, value reflect.Value, val string) error { - if !IsEmpty(value) { + if !rutil.IsEmpty(value) { return nil } switch value.Kind() { diff --git a/config/reflect_test.go b/config/reflect_test.go index be43850a..1abbe9fa 100644 --- a/config/reflect_test.go +++ b/config/reflect_test.go @@ -3,7 +3,7 @@ package config_test import ( "testing" - "github.com/unistack-org/micro/v3/config" + rutil "github.com/unistack-org/micro/v3/util/reflect" ) type Config struct { @@ -18,7 +18,7 @@ type SubConfig struct { func TestReflect(t *testing.T) { cfg1 := &Config{Value: "cfg1", Config: &Config{Value: "cfg1_1"}, SubConfig: &SubConfig{Value: "cfg1"}} - cfg2, err := config.Zero(cfg1) + cfg2, err := rutil.Zero(cfg1) if err != nil { t.Fatal(err) } diff --git a/config/reflect.go b/util/reflect/reflect.go similarity index 91% rename from config/reflect.go rename to util/reflect/reflect.go index fd84a62b..dcac5d45 100644 --- a/config/reflect.go +++ b/util/reflect/reflect.go @@ -1,9 +1,14 @@ -package config +package reflect import ( + "errors" "reflect" ) +var ( + ErrInvalidStruct = errors.New("invalid struct specified") +) + func IsEmpty(v reflect.Value) bool { switch v.Kind() { case reflect.Array, reflect.Map, reflect.Slice, reflect.String: