Documentation ¶
Overview ¶
Package reflecttools provides utility functions for working with Go's reflect package.
These functions are highly specific to Granitic's internal use of reflection and are not recommended for use in user applications.
Index ¶
- func ExtractDotPath(path string) []string
- func FieldValue(i interface{}, name string) reflect.Value
- func FindNestedField(path []string, v interface{}) (reflect.Value, error)
- func HasFieldOfName(i interface{}, fieldName string) bool
- func HasWritableFieldOfName(i interface{}, fieldName string) bool
- func IsPointer(p interface{}) bool
- func IsPointerToStruct(p interface{}) bool
- func IsSliceOrArray(i interface{}) bool
- func IsZero(i interface{}) bool
- func NilMap(v reflect.Value) bool
- func NilPointer(v reflect.Value) bool
- func SetBool(i interface{}, name string, b bool)
- func SetFieldPtrToStruct(field reflect.Value, valuePointer interface{}) error
- func SetFloat64(i interface{}, name string, v float64)
- func SetInt64(i interface{}, name string, v int64)
- func SetPtrToStruct(target interface{}, field string, valuePointer interface{}) error
- func SetSliceElem(i interface{}, fieldName string, value interface{}, index int)
- func SetString(i interface{}, name string, s string)
- func SetUint64(i interface{}, name string, v uint64)
- func StructOrPointerHasFieldOfName(i interface{}, fieldName string) bool
- func TargetFieldIsArray(i interface{}, name string) bool
- func TypeOfField(i interface{}, name string) reflect.Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractDotPath ¶
ExtractDotPath converts a dot-delimited path into a string array of its constiuent parts. E.g. "a.b.c" becomes ["a","b","c"]
func FieldValue ¶
FieldValue assumes the supplied interface is a pointer to a struct, an interface or a struct and has a valid field of the supplied name, then returns the reflect value of that field.
func FindNestedField ¶
FindNestedField take the output of ExtractDotPath and uses it to traverse an object graph to find a value. Apart from final value, each intermediate step in the graph must be a struct or pointer to a struct.
func HasFieldOfName ¶
HasFieldOfName assumes the supplied interface is a pointer to a struct and checks to see if the underlying struct has a field of the supplied name. It does not check to see if the field is writable.
func HasWritableFieldOfName ¶
HasWritableFieldOfName assumes the supplied interface is a pointer to a struct and checks to see if the underlying struct has a writable field of the supplied name.
func IsPointer ¶
func IsPointer(p interface{}) bool
IsPointer returns true if the supplied object is a pointer type
func IsPointerToStruct ¶
func IsPointerToStruct(p interface{}) bool
IsPointerToStruct returns true if the supplied interfaces is a pointer to a struct.
func IsSliceOrArray ¶
func IsSliceOrArray(i interface{}) bool
IsSliceOrArray returns true if the supplied value is a slice or an array
func IsZero ¶
func IsZero(i interface{}) bool
IsZero returns true if i is set to the zero value of i's type
func NilPointer ¶
NilPointer returns true if the supplied reflect value is a pointer that does not point a valid value.
func SetBool ¶
SetBool assumes that the supplied interface is a pointer to a struct and has a writable bool field of the supplied name, then sets the field of the supplied value.
func SetFieldPtrToStruct ¶
SetFieldPtrToStruct assigns the supplied object to the supplied reflect Value (which represents a field on a struct). Returns an error if the supplied type is an interface and the target field cannot be set o
func SetFloat64 ¶
SetFloat64 assumes that the supplied interface is a pointer to a struct and has a writable float64 field of the supplied name, then sets the field of the supplied value.
func SetInt64 ¶
SetInt64 assumes that the supplied interface is a pointer to a struct and has a writable int64 field of the supplied name, then sets the field of the supplied value.
func SetPtrToStruct ¶
SetPtrToStruct is used to inject an object into the specified field on a another object. The target object, supplied value and the type of the named target field must all be a pointer to a struct.
func SetSliceElem ¶ added in v2.2.0
SetSliceElem assumes that the supplied interface is a slice or array and then sets the element at the index to the supplied value
func SetString ¶
SetString assumes that the supplied interface is a pointer to a struct and has a writable string field of the supplied name, then sets the field of the supplied value.
func SetUint64 ¶
SetUint64 assumes that the supplied interface is a pointer to a struct and has a writable uint64 field of the supplied name, then sets the field of the supplied value.
func StructOrPointerHasFieldOfName ¶ added in v2.2.0
StructOrPointerHasFieldOfName checks whether the supplied object has a field of the specified name
func TargetFieldIsArray ¶
TargetFieldIsArray assumes the supplied interface is a pointer to a struct, an interface or a struct and has a valid field of the supplied name, then returns true if the reflect type of that field is Array. Note that this method will return false for Slice fields.
func TypeOfField ¶
TypeOfField assumes the supplied interface is a pointer to a struct and that the supplied field name exists on that struct, then finds the reflect type of that field.
Types ¶
This section is empty.