util/reflect: fix time.Time StructFields parsing
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
887b48f1e7
commit
598dddc476
@ -7,6 +7,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrInvalidParam specifies invalid url query params
|
// ErrInvalidParam specifies invalid url query params
|
||||||
@ -14,6 +15,8 @@ var ErrInvalidParam = errors.New("invalid url query param provided")
|
|||||||
|
|
||||||
var bracketSplitter = regexp.MustCompile(`\[|\]`)
|
var bracketSplitter = regexp.MustCompile(`\[|\]`)
|
||||||
|
|
||||||
|
var timeKind = reflect.TypeOf(time.Time{}).Kind()
|
||||||
|
|
||||||
type StructField struct {
|
type StructField struct {
|
||||||
Field reflect.StructField
|
Field reflect.StructField
|
||||||
Value reflect.Value
|
Value reflect.Value
|
||||||
@ -121,13 +124,16 @@ func StructFields(src interface{}) ([]StructField, error) {
|
|||||||
if !val.CanSet() || len(fld.PkgPath) != 0 {
|
if !val.CanSet() || len(fld.PkgPath) != 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if val.Kind() == reflect.Struct {
|
switch val.Kind() {
|
||||||
|
case timeKind:
|
||||||
|
fields = append(fields, StructField{Field: fld, Value: val})
|
||||||
|
case reflect.Struct:
|
||||||
infields, err := StructFields(val.Interface())
|
infields, err := StructFields(val.Interface())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fields = append(fields, infields...)
|
fields = append(fields, infields...)
|
||||||
} else {
|
default:
|
||||||
fields = append(fields, StructField{Field: fld, Value: val})
|
fields = append(fields, StructField{Field: fld, Value: val})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user