granitic: github.com/graniticio/granitic/reflecttools Index | Files

package reflecttools

import "github.com/graniticio/granitic/reflecttools"

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

Package Files

reflecttools.go

func ExtractDotPath Uses

func ExtractDotPath(path string) []string

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 Uses

func FieldValue(i interface{}, name string) reflect.Value

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 Uses

func FindNestedField(path []string, v interface{}) (reflect.Value, error)

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 Uses

func HasFieldOfName(i interface{}, fieldName string) bool

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 Uses

func HasWritableFieldOfName(i interface{}, fieldName string) bool

HasFieldOfName 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 Uses

func IsPointer(p interface{}) bool

func IsPointerToStruct Uses

func IsPointerToStruct(p interface{}) bool

IsPointerToStruct returns true if the supplied interfaces is a pointer to a struct.

func IsSliceOrArray Uses

func IsSliceOrArray(i interface{}) bool

func IsZero Uses

func IsZero(i interface{}) bool

IsZero returns true if i is set to the zero value of i's type

func NilMap Uses

func NilMap(v reflect.Value) bool

NilPointer returns true is the supplied reflect value is a Map and is nil.

func NilPointer Uses

func NilPointer(v reflect.Value) bool

NilPointer returns true if the supplied reflect value is a pointer that does not point a valid value.

func SetBool Uses

func SetBool(i interface{}, name string, b bool)

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 Uses

func SetFieldPtrToStruct(tfv reflect.Value, valuePointer interface{}) error

func SetFloat64 Uses

func SetFloat64(i interface{}, name string, v float64)

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 Uses

func SetInt64(i interface{}, name string, v int64)

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 Uses

func SetPtrToStruct(target interface{}, field string, valuePointer interface{}) error

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 SetString Uses

func SetString(i interface{}, name string, s string)

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 Uses

func SetUint64(i interface{}, name string, v uint64)

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 TargetFieldIsArray Uses

func TargetFieldIsArray(i interface{}, name string) bool

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 Uses

func TypeOfField(i interface{}, name string) reflect.Type

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.

Package reflecttools imports 4 packages (graph) and is imported by 6 packages. Updated 2018-01-11. Refresh now. Tools for package owners.