Skip to content

Commit

Permalink
⚙️ refactor: Change the writing style
Browse files Browse the repository at this point in the history
  • Loading branch information
sohaha committed Dec 2, 2024
1 parent 3abc61a commit 692df43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions zreflect/quick.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ func ForEachMethod(valof reflect.Value, fn func(index int, method reflect.Method
return nil
}

var (
// SkipChild Field is returned when a struct field is skipped.
SkipChild = errors.New("skip struct")
)
// SkipChild Field is returned when a struct field is skipped.
var SkipChild = errors.New("skip struct")

// ForEach For Each Struct field
func ForEach(typ reflect.Type, fn func(parent []string, index int, tag string, field reflect.StructField) error) (err error) {
var forField func(typ reflect.Type, parent []string) error
if typ.Kind() == reflect.Pointer {
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
forField = func(typ reflect.Type, parent []string) error {
Expand Down Expand Up @@ -63,9 +61,8 @@ func ForEachValue(val reflect.Value, fn func(parent []string, index int, tag str
if !Nonzero(val) {
return errors.New("reflect.Value is zero")
}
if val.Kind() == reflect.Pointer {
val = val.Elem()
}

val = reflect.Indirect(val)
typ := toRType(NewType(val))
var forField func(val reflect.Value, typ reflect.Type, parent []string) error
forField = func(val reflect.Value, typ reflect.Type, parent []string) error {
Expand Down
2 changes: 1 addition & 1 deletion ztype/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (d *Conver) toMapFromStruct(name string, dataVal reflect.Value, val reflect
return fmt.Errorf("cannot assign type '%s' to map value field of type '%s'", vTyp, valMap.Type().Elem())
}

if vTyp.Kind() == reflect.Pointer && !v.IsZero() {
if vTyp.Kind() == reflect.Ptr && !v.IsZero() {
vTyp = v.Elem().Type()
}

Expand Down

0 comments on commit 692df43

Please sign in to comment.