Documentation
¶
Overview ¶
Package strct a simplified golang reflect package
The struct package takes the complexety of golang reflecs away by giving you 2 functions to work with: the scanner and the parser. The scanner takes the object that needs to be scanned and a function that goes over each type property of the struct of the given object. The scanner function has 2 parameters: the reflect.Structfield which contains the data such as the property name and the property tags and contains a pointer to the reflect.Value which you than can either interface with or set a new value of.
You can easaly set a new value using the Parser the parser takes the value that needs to be set as string (because its univerably accessable) and the reflect.Value pointer that needs to be set.
Usage ¶
Get the values you need using the scanner
func TagEnvParser(obj interface{}, parsevalue string) error {
return strct.Scan(obj, func(field reflect.StructField, value *reflect.Value) error {
tagVal := field.Tag.Get(`env`)
if tagVal == `` {
return nil
}
strct.Parse(os.GetEnv(tagval), value)
})
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoPtr = fmt.Errorf(`insert is not a pointer or a struct`)
ErrNoPtr gets thrown if the inserted object is not a pointer or a struct type
Functions ¶
Types ¶
This section is empty.