Skip to content

Commit

Permalink
config: move reflect stuff to util/reflect
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Tolstov <[email protected]>
  • Loading branch information
vtolstov committed Jan 18, 2021
1 parent 4783c6d commit 770e842
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"reflect"
"strconv"
"strings"

rutil "github.com/unistack-org/micro/v3/util/reflect"
)

type defaultConfig struct {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions config/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion config/reflect.go → util/reflect/reflect.go
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 770e842

Please sign in to comment.