Documentation
¶
Index ¶
- Variables
- func DerefType(t reflect.Type) reflect.Type
- func DerefValue(val any) reflect.Value
- func DerefValueAndType(val any) (reflect.Value, reflect.Type)
- func EnumFlatExportedStructFields(val any, callback func(reflect.StructField, reflect.Value))
- func FlatExportedStructFieldValueNameMap(val any, nameTag string) map[string]StructFieldValueName
- func FlatExportedStructFieldsIter(s any) iter.Seq2[reflect.StructField, reflect.Value]
- func FlatStructFieldCount(t reflect.Type) int
- func FlatStructFieldNames(t reflect.Type) (names []string)
- func FlatStructFieldTags(t reflect.Type, tagKey string) (tagValues []string)
- func FlatStructFieldTagsOrNames(t reflect.Type, tagKey string) (tagsOrNames []string)
- func FlatStructFieldValues(v reflect.Value) (values []reflect.Value)
- func IsNil(v reflect.Value) bool
- func IsZero(v any) bool
- func ValueOf(val any) reflect.Value
- func ValuesToInterfaces(values ...reflect.Value) []any
- func ZeroValueExportedStructFieldNames(st any, namePrefix, nameTag string, namesToValidate ...string) (zeroNames []string)
- type FieldError
- type NamedStructField
- type StructFieldValue
- type StructFieldValueName
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func DerefValue ¶
DerefValue dereferences val until a non pointer type or nil is found
func EnumFlatExportedStructFields ¶
func EnumFlatExportedStructFields(val any, callback func(reflect.StructField, reflect.Value))
EnumFlatExportedStructFields returns reflect.StructField and reflect.Value of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. The argument val can be a struct, a pointer to a struct, or a reflect.Value.
func FlatExportedStructFieldValueNameMap ¶
func FlatExportedStructFieldValueNameMap(val any, nameTag string) map[string]StructFieldValueName
FlatExportedStructFieldValueNameMap returns a slice of StructFieldValueName of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. The argument val can be a struct, a pointer to a struct, or a reflect.Value.
func FlatExportedStructFieldsIter ¶
FlatExportedStructFieldsIter returns an iterator over flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. The argument s can be a struct, a pointer to a struct, or a reflect.Value.
func FlatStructFieldCount ¶
FlatStructFieldCount returns the number of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct.
func FlatStructFieldNames ¶
FlatStructFieldNames returns the names of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct.
func FlatStructFieldTags ¶
FlatStructFieldTags returns the tag values for a tagKey of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. An empty string is returned for fields that don't have a matching tag.
func FlatStructFieldTagsOrNames ¶
FlatStructFieldTagsOrNames returns the tag values for tagKey or the names of the field if no tag with tagKey is defined at a struct field. Fields are flattened, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct.
func FlatStructFieldValues ¶
FlatStructFieldValues returns the values of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct.
func IsNil ¶
IsNil returns if val is of a type that can be nil and if it is nil. Unlike reflect.Value.IsNil() it is safe to call this function for any value and type. The zero value of reflect.Value will yield true because it can be the result of reflect.ValueOf(nil)
func IsZero ¶
IsZero returns if underlying value of v is the zero (default) value of its type, or if v itself is nil.
func ValueOf ¶
ValueOf differs from reflect.ValueOf in that it returns the argument val casted to reflect.Value if val is alread a reflect.Value. Else the standard result of reflect.ValueOf(val) will be returned.
func ValuesToInterfaces ¶
ValuesToInterfaces returns a slice of interface{} by calling reflect.Value.Interfac() for all values.
func ZeroValueExportedStructFieldNames ¶
func ZeroValueExportedStructFieldNames(st any, namePrefix, nameTag string, namesToValidate ...string) (zeroNames []string)
ZeroValueExportedStructFieldNames returns the names of exported zero (default) value struct fields. If a struct field has a tag with the key nameTag, then the tag value will be used as field name, else the Go struct field name will be used. All returned names are prefixed with namePrefix. Anonymous sub structs will be flattened, named sub structs are checked recursively with their name used as prefix delimited with a point. Zero array and slice fields will be added with thair name and index formated as "%s[%d]".
Types ¶
type FieldError ¶
func ValidateStructFields ¶
func (FieldError) Error ¶
func (f FieldError) Error() string
type NamedStructField ¶
type NamedStructField struct { Field reflect.StructField Name string }
func FlatExportedNamedStructFields ¶
func FlatExportedNamedStructFields(t reflect.Type, nameTag string) []NamedStructField
FlatExportedNamedStructFields returns a slice of NamedStructField of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. The argument t can be a struct, a pointer to a struct, or a reflect.Value.
type StructFieldValue ¶
type StructFieldValue struct { Field reflect.StructField Value reflect.Value }
func FlatExportedStructFields ¶
func FlatExportedStructFields(val any) []StructFieldValue
FlatExportedStructFields returns a slice of StructFieldValue of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. The argument val can be a struct, a pointer to a struct, or a reflect.Value.
type StructFieldValueName ¶
type StructFieldValueName struct { Field reflect.StructField Value reflect.Value Name string }
func FlatExportedStructFieldValueNames ¶
func FlatExportedStructFieldValueNames(val any, nameTag string) []StructFieldValueName
FlatExportedStructFieldValueNames returns a slice of StructFieldValueName of flattened struct fields, meaning that the fields of anonoymous embedded fields are flattened to the top level of the struct. The argument val can be a struct, a pointer to a struct, or a reflect.Value.