Skip to content

Commit

Permalink
enhance gogf#3221
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git committed Dec 21, 2023
1 parent 4cce855 commit 3f36236
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions util/gutil/gutil_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func FillStructWithDefault(structPtr interface{}) error {
return err
}
for _, field := range fields {
if field.Kind() == reflect.Struct {
err := FillStructWithDefault(field.Value.Addr())
if err != nil {
return err
}
continue
}

if defaultValue := field.TagDefault(); defaultValue != "" {
if field.IsEmpty() {
field.Value.Set(reflect.ValueOf(
Expand All @@ -97,5 +105,6 @@ func FillStructWithDefault(structPtr interface{}) error {
}
}
}

return nil
}

0 comments on commit 3f36236

Please sign in to comment.