Documentation ¶
Index ¶
- func ParseTag(tag string) (map[string]string, error)
- type CallResult
- type Obj
- func (o *Obj) Field(fieldName string) *ObjField
- func (o *Obj) Fields() []ObjField
- func (o Obj) FieldsAll() []ObjField
- func (o Obj) FieldsAnonymous() []ObjField
- func (o Obj) FieldsFlattened() []ObjField
- func (o Obj) FindDoubleFields() []string
- func (o *Obj) GetByIndex(index int) (value interface{}, found bool)
- func (o *Obj) GetByKey(key interface{}) (value interface{}, found bool)
- func (o *Obj) IsGettableByIndex() bool
- func (o *Obj) IsMap() bool
- func (o Obj) IsPtr() bool
- func (o *Obj) IsSettableByIndex() bool
- func (o *Obj) IsValid() bool
- func (o *Obj) Keys() ([]interface{}, error)
- func (o Obj) Kind() reflect.Kind
- func (o *Obj) Len() int
- func (o *Obj) Method(name string) *ObjMethod
- func (o *Obj) Methods() []ObjMethod
- func (o *Obj) SetByIndex(index int, val interface{}) error
- func (o *Obj) SetByKey(key interface{}, val interface{}) (err error)
- func (o Obj) String() string
- func (o Obj) Type() reflect.Type
- type ObjField
- func (of *ObjField) Get() (interface{}, error)
- func (of *ObjField) IsAnonymous() bool
- func (of *ObjField) IsExported() bool
- func (of *ObjField) IsSettable() bool
- func (of *ObjField) IsValid() bool
- func (of *ObjField) Kind() reflect.Kind
- func (of *ObjField) Name() string
- func (of *ObjField) Set(value interface{}) error
- func (of *ObjField) Tag(tag string) (string, error)
- func (of *ObjField) TagExpanded(tag string) ([]string, error)
- func (of *ObjField) Tags() (map[string]string, error)
- func (of *ObjField) TagsString() (string, error)
- func (of *ObjField) Type() reflect.Type
- type ObjFieldMetadata
- type ObjMetadata
- type ObjMethod
- type ObjMethodMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallResult ¶
type CallResult struct { Result []interface{} Error error }
CallResult is a wrapper of a method call result.
func (*CallResult) IsError ¶
func (cr *CallResult) IsError() bool
IsError checks if the last value is a non-nil error.
type Obj ¶
type Obj struct { ObjMetadata // contains filtered or unexported fields }
Obj is a wrapper for golang values which need to be reflected. The value can be of any kind and any type.
func NewFromType ¶
NewFromType creates a new Obj but using reflect.Type.
func (*Obj) Field ¶
Field get a field wrapper. Note that the field name can be invalid. You can check the field validity using ObjField.IsValid().
func (*Obj) Fields ¶
Fields returns fields. Don't list fields inside Anonymous fields as distinct fields.
func (Obj) FieldsAll ¶
FieldsAll returns fields. List both anonymous fields and fields declared inside anonymous fields.
func (Obj) FieldsAnonymous ¶
FieldsAnonymous returns only anonymous fields.
func (Obj) FieldsFlattened ¶
FieldsFlattened returns fields. Will not list Anonymous fields but it will list fields declared in those anonymous fields.
func (Obj) FindDoubleFields ¶
FindDoubleFields checks if this object has declared multiple fields with a same name. (by checking recursively Anonymous fields and their fields)
func (*Obj) GetByIndex ¶ added in v0.5.3
GetByIndex returns a value by int index.
Works for arrays, slices and strins. Won't panic when index or kind is invalid.
func (*Obj) GetByKey ¶ added in v0.5.3
GetByKey returns a value by map key.
Won't panic when key is invalid or kind is not map.
func (*Obj) IsGettableByIndex ¶ added in v0.5.4
IsGettableByIndex returns true if underlying type is array, slice or string
func (*Obj) IsMap ¶ added in v0.5.4
IsMap returns true if underlying type is map or a pointer to a map
func (*Obj) IsSettableByIndex ¶ added in v0.5.4
IsSettableByIndex returns true if underlying type is array, slice (but not string, since they are immutable)
func (*Obj) IsValid ¶
IsValid checks if the underlying objects is valid. Nil is an invalid value, for example.
func (*Obj) Len ¶ added in v0.5.3
Len returns object length. Works for arrays, channels, maps, slices and strings.
It doesn't panic for other types, returns 0 instead.
In case the value is a pointer, len checks the underlying value.
func (*Obj) Method ¶
Method returns a new method wrapper. The method name can be invalid, check the method validity with ObjMethod.IsValid().
func (*Obj) SetByIndex ¶ added in v0.5.3
SetByIndex sets a slice value by key.
type ObjField ¶
type ObjField struct { ObjFieldMetadata // contains filtered or unexported fields }
ObjField is a wrapper for the object's field.
func (*ObjField) IsAnonymous ¶
IsAnonymous checks if this is an anonymous (embedded) field.
func (*ObjField) IsExported ¶
IsExported returns true if the name starts with uppercase (i.e. field is public).
func (*ObjField) IsSettable ¶
IsSettable checks if this field is settable.
func (*ObjField) Set ¶
Set sets a value for this field or error if field is invalid (or not settable).
func (*ObjField) TagExpanded ¶
TagExpanded returns the tag value "expanded" with commas.
func (*ObjField) TagsString ¶ added in v0.5.6
TagsString returns the complete tags string (everything inside “)
type ObjFieldMetadata ¶
type ObjFieldMetadata struct {
// contains filtered or unexported fields
}
ObjFieldMetadata contains data which is always unique per Type/Field.
type ObjMetadata ¶
type ObjMetadata struct {
// contains filtered or unexported fields
}
ObjMetadata contains data which is always unique per Type.
func (*ObjMetadata) IsStructOrPtrToStruct ¶
func (om *ObjMetadata) IsStructOrPtrToStruct() bool
IsStructOrPtrToStruct checks if the value is a struct or a pointer to a struct.
type ObjMethod ¶
type ObjMethod struct { ObjMethodMetadata // contains filtered or unexported fields }
ObjMethod is a wrapper for an object method. The name of the method can be invalid.
func (*ObjMethod) Call ¶
func (om *ObjMethod) Call(args ...interface{}) (*CallResult, error)
Call calls this method. Note that in the error returning value is not the error from the method call.
type ObjMethodMetadata ¶
type ObjMethodMetadata struct {
// contains filtered or unexported fields
}
ObjMethodMetadata contains data which is always unique per Type/Method.