field: add IsEmbedded and fix doc about Value()
This commit is contained in:
parent
fe137c012f
commit
53f565ab3e
12
field.go
12
field.go
@ -2,19 +2,25 @@ package structure
|
|||||||
|
|
||||||
import "reflect"
|
import "reflect"
|
||||||
|
|
||||||
// Field represents a single struct field that encapsulates many high level
|
// Field represents a single struct field that encapsulates high level
|
||||||
// function around a singel struct field
|
// functions around the field.
|
||||||
type Field struct {
|
type Field struct {
|
||||||
value reflect.Value
|
value reflect.Value
|
||||||
field reflect.StructField
|
field reflect.StructField
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// such key in the tag, Tag returns the empty string
|
// such key in the tag, Tag returns the empty string.
|
||||||
func (f *Field) Tag(key string) string {
|
func (f *Field) Tag(key string) string {
|
||||||
return f.field.Tag.Get(key)
|
return f.field.Tag.Get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Value returns the underlying value of of the field.
|
||||||
func (f *Field) Value() interface{} {
|
func (f *Field) Value() interface{} {
|
||||||
return f.value.Interface()
|
return f.value.Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEmbedded returns true if the given field is an anonymous field (embedded)
|
||||||
|
func (f *Field) IsEmbedded() bool {
|
||||||
|
return f.field.Anonymous
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user