Documentation
¶
Overview ¶
Package structs provides reflection based utilities for working with structs.
structs was primarily created to provide a way to initialize a struct of string properties with the values of the property names. In this way we can mimic the ability to initialize nested consts available in other languages. It is based on reflection so does have a performance penalty however it is meant to be used as a global var or initialized with init for a one time cost
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct provides a reflection wrapper for structs
func New ¶
func New(obj interface{}) (new *Struct)
New converts a given struct to a *Struct to work with it in reflection; panics if obj is not a non nil struct/*struct type.
func (*Struct) Fields ¶
func (st *Struct) Fields() (fields []reflect.StructField)
Fields returns all the field names as a []string
func (*Struct) SetFieldByIndex ¶
SetFieldByIndex sets the value of the field to the given value if they are the same type; Sets private or public fields as called out by the index i. Optionially takes the value's type and the field's value.