Documentation
¶
Index ¶
- Constants
- func MarshalValue(v interface{}, seps []rune) (interface{}, error)
- func Set(value reflect.Value, v interface{}, seps []rune) error
- func UnmarshalValue(value reflect.Value, s string, seps []rune) error
- type StructField
- func (f *StructField) Embedded() *StructStruct
- func (f *StructField) Interface() interface{}
- func (f *StructField) MarshalValue() (interface{}, error)
- func (f *StructField) Name() string
- func (f *StructField) PtrValue() interface{}
- func (f *StructField) Separators() []rune
- func (f *StructField) Set(v interface{}) error
- func (f *StructField) Tag() reflect.StructTag
- type StructStruct
- func (s *StructStruct) Call(m string, args []interface{}) ([]interface{}, bool)
- func (s *StructStruct) CallUntil(m string, args []interface{}, until func([]interface{}) bool) ([]interface{}, bool)
- func (s *StructStruct) Fields() []*StructField
- func (s *StructStruct) GoString() string
- func (s *StructStruct) Inlined() bool
- func (s *StructStruct) Interface() interface{}
- func (s *StructStruct) Lookup(path ...string) *StructField
- func (s *StructStruct) Name() string
- func (s *StructStruct) String() string
Constants ¶
const ( // SliceSeparator is used to separate slice and map items. SliceSeparator = ',' // MapKeySeparator is used to separate map keys and their value. MapKeySeparator = ':' )
Variables ¶
This section is empty.
Functions ¶
func MarshalValue ¶
MarshalValue converts v into a higher level value or a string as follows:
- int, int8, int16, int32 -> int64
- uint, uint8, uint16, uint32 -> uint64
- float32 -> float64
- any slice/map/array -> string
- time.Time, *text/template.Template, *html/template.Template, *regexp.RegExp, *url.URL -> string
- *net.IPAddr, *net.IPNet -> string
- encoding.TextMarshaler -> string
The following types are returned as is:
- bool, time.Duration, float64, int64, string, uint64
sliceSep, mapKeySep
Types ¶
type StructField ¶
type StructField struct {
// contains filtered or unexported fields
}
StructField represents a struct field.
func (*StructField) Embedded ¶
func (f *StructField) Embedded() *StructStruct
Embedded returns the embedded struct if the field is embedded.
func (*StructField) Interface ¶
func (f *StructField) Interface() interface{}
Interface returns the interface value of the field.
func (*StructField) MarshalValue ¶
func (f *StructField) MarshalValue() (interface{}, error)
MarshalValue returns the field value marshaled by MarshalValue().
func (*StructField) PtrValue ¶
func (f *StructField) PtrValue() interface{}
PtrValue returns the interface pointer value of the field.
func (*StructField) Separators ¶
func (f *StructField) Separators() []rune
Separators returns the field separators.
func (*StructField) Set ¶
func (f *StructField) Set(v interface{}) error
Set assigns the given value to the field. If the value is a string but the field is not, then its value is deserialized using encoding.Unmarshaler or in a best effort way.
func (*StructField) Tag ¶
func (f *StructField) Tag() reflect.StructTag
Tag returns the tags defined on the field.
type StructStruct ¶
type StructStruct struct {
// contains filtered or unexported fields
}
StructStruct represents a decomposed struct.
func NewStruct ¶
func NewStruct(s interface{}, tagid, septagid string) (*StructStruct, error)
NewStruct recursively decomposes the input struct into its fields and embedded structs. Fields tags with "-" will be skipped. Fields tags with a non empty value will be renamed to that value.
The input must be a pointer to a struct.
func (*StructStruct) Call ¶
func (s *StructStruct) Call(m string, args []interface{}) ([]interface{}, bool)
Call invokes the method m on s with arguments args.
It returns the method results and whether is was invoked successfully.
func (*StructStruct) CallUntil ¶
func (s *StructStruct) CallUntil(m string, args []interface{}, until func([]interface{}) bool) ([]interface{}, bool)
CallUntil recursively calls the given method on its StructStruct fields and stops at the first one satisfying the stop condition.
func (*StructStruct) Fields ¶
func (s *StructStruct) Fields() []*StructField
Fields returns all the fields of the parsed struct.
func (*StructStruct) GoString ¶
func (s *StructStruct) GoString() string
GoString is used to debug a StructStruct and returns a full and human readable representation of its elements.
func (*StructStruct) Inlined ¶
func (s *StructStruct) Inlined() bool
Inlined returns whether or not the struct is inlined.
func (*StructStruct) Interface ¶
func (s *StructStruct) Interface() interface{}
Interface returns the raw interface of the underlying struct.
func (*StructStruct) Lookup ¶
func (s *StructStruct) Lookup(path ...string) *StructField
Lookup returns the field for the corresponding path.
func (*StructStruct) Name ¶
func (s *StructStruct) Name() string
Name returns the underlying type name.
func (*StructStruct) String ¶
func (s *StructStruct) String() string
String gives a simple string representation of the StructStruct.