refactor Field to have defaultTag field which value is from parent struct
This commit is contained in:
parent
a093a86a06
commit
79afa3ec1c
7
field.go
7
field.go
@ -14,8 +14,9 @@ var (
|
|||||||
// Field represents a single struct field that encapsulates high level
|
// Field represents a single struct field that encapsulates high level
|
||||||
// functions around the field.
|
// functions around the field.
|
||||||
type Field struct {
|
type Field struct {
|
||||||
value reflect.Value
|
value reflect.Value
|
||||||
field reflect.StructField
|
field reflect.StructField
|
||||||
|
defaultTag string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tag returns the value associated with key in the tag string. If there is no
|
// Tag returns the value associated with key in the tag string. If there is no
|
||||||
@ -92,7 +93,7 @@ func (f *Field) Set(val interface{}) error {
|
|||||||
//
|
//
|
||||||
// It panics if field is not exported or if field's kind is not struct
|
// It panics if field is not exported or if field's kind is not struct
|
||||||
func (f *Field) Fields() []*Field {
|
func (f *Field) Fields() []*Field {
|
||||||
return getFields(f.value, DefaultTagName)
|
return getFields(f.value, f.defaultTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field returns the field from a nested struct. It panics if the nested struct
|
// Field returns the field from a nested struct. It panics if the nested struct
|
||||||
|
|||||||
@ -222,8 +222,9 @@ func (s *Struct) FieldOk(name string) (*Field, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Field{
|
return &Field{
|
||||||
field: field,
|
field: field,
|
||||||
value: s.value.FieldByName(name),
|
value: s.value.FieldByName(name),
|
||||||
|
defaultTag: s.TagName,
|
||||||
}, true
|
}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user