Documentation ¶
Index ¶
- func GetStructField(structInstance interface{}, fieldname string) reflect.Value
- func GetUnexportedField(structInstance interface{}, fieldname string) interface{}
- func SetUnexportedField(structInstance interface{}, fieldname string, value interface{})
- func SizeOf(v interface{}) int
- func ToMap(v interface{}, tomapkey ToMapKey, unexported bool) (map[string]interface{}, error)
- func ToMapWithDefault(v interface{}) (map[string]interface{}, error)
- func UnwrapUnexportedField(field reflect.Value) interface{}
- type ToMapKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStructField ¶ added in v0.0.8
GetStructField obtains a reference to a field of a pointer to a struct
func GetUnexportedField ¶ added in v0.0.8
func GetUnexportedField(structInstance interface{}, fieldname string) interface{}
GetUnexportedField unwraps an unexported field with pointer to struct and field name
func SetUnexportedField ¶ added in v0.0.8
func SetUnexportedField(structInstance interface{}, fieldname string, value interface{})
SetUnexportedField sets (pointer to) struct's field with the specified value
func SizeOf ¶ added in v0.2.0
func SizeOf(v interface{}) int
SizeOf returns the size of 'v' in bytes. If there is an error during calculation, Of returns -1.
Implementation is taken from https://github.com/DmitriyVTitov/size/blob/v1.5.0/size.go#L14 which in turn is inspired from binary.Size of stdlib
func ToMap ¶
ToMap converts exported fields of a struct to map[string]interface{} - non exported fields are converted to string
func ToMapWithDefault ¶
ToMapWithDefault settings
func UnwrapUnexportedField ¶ added in v0.0.8
UnwrapUnexportedField unwraps an unexported field
Types ¶
type ToMapKey ¶
var TitleUnderscore ToMapKey = func(raw string) string { newstr := make([]rune, 0, len(raw)) for i, chr := range raw { if isUpper := 'A' <= chr && chr <= 'Z'; isUpper { if i > 0 { newstr = append(newstr, '_') } chr -= 'A' - 'a' } newstr = append(newstr, chr) } return string(newstr) }
TitleUnderscore from https://github.com/go-ini/ini/blob/5e97220809ffaa826f787728501264e9114cb834/struct.go#L46