Documentation ¶
Index ¶
- Constants
- Variables
- func BuildTypeName(t reflect.Type) string
- func FormatValue(value interface{}) string
- func InvokeMethod(target interface{}, name string, args ...interface{}) ([]reflect.Value, error)
- func IsMethodNotFound(err error) bool
- func IsPrimitiveValue(v reflect.Value) bool
- func JSONMergeStruct(dest, src interface{})
- func ReflectRecursive(v reflect.Value, visitor visitorFunc, options *ReflectOptions) error
- func RegisterPrinter(p Printer)
- func SetString(target interface{}, targetPath string, newValue string) error
- func Unset(target interface{}, targetPath string) error
- func ValueAsString(value reflect.Value) string
- type FieldPath
- type FieldPathElement
- type FieldPathElementType
- type MethodNotFoundError
- type Printer
- type ReflectOptions
Constants ¶
const ( FieldPathElementTypeField = iota FieldPathElementTypeMapKey FieldPathElementTypeArrayIndex FieldPathElementTypeWildcardIndex )
Variables ¶
var SkipReflection = errors.New("skip this value")
Functions ¶
func BuildTypeName ¶
func FormatValue ¶
func FormatValue(value interface{}) string
FormatValue returns a string representing the value
func InvokeMethod ¶
InvokeMethod calls the specified method by reflection
func IsMethodNotFound ¶
func IsPrimitiveValue ¶
IsPrimitiveValue returns true if passed a value of primitive type: int, bool, etc Note that string (like []byte) is not treated as a primitive type
func JSONMergeStruct ¶ added in v1.19.0
func JSONMergeStruct(dest, src interface{})
JSONMergeStruct merges src into dest It uses a JSON marshal & unmarshal, so only fields that are JSON-visible will be copied If both source and destination has a value for a field, source takes presedence
func ReflectRecursive ¶
func ReflectRecursive(v reflect.Value, visitor visitorFunc, options *ReflectOptions) error
ReflectRecursive calls visitor with v and every recursive sub-value, skipping subtrees if SkipReflection is returned
func RegisterPrinter ¶
func RegisterPrinter(p Printer)
RegisterPrinter adds a custom printer function
func ValueAsString ¶
ValueAsString returns a human-readable string representation of the passed value
Types ¶
type FieldPath ¶ added in v1.19.0
type FieldPath struct {
// contains filtered or unexported fields
}
func ParseFieldPath ¶ added in v1.19.0
func (*FieldPath) Extend ¶ added in v1.19.0
func (f *FieldPath) Extend(el FieldPathElement) *FieldPath
func (*FieldPath) HasPrefixMatch ¶ added in v1.19.0
type FieldPathElement ¶ added in v1.19.0
type FieldPathElement struct { Type FieldPathElementType // contains filtered or unexported fields }
type FieldPathElementType ¶ added in v1.19.0
type FieldPathElementType int
type MethodNotFoundError ¶
type MethodNotFoundError struct { Name string Target interface{} }
func (*MethodNotFoundError) Error ¶
func (e *MethodNotFoundError) Error() string
type Printer ¶
Printer is a custom printer function, so we can add special display for objects (without introducing a package dependency)
type ReflectOptions ¶ added in v1.19.0
type ReflectOptions struct { // JSONNames means the elements of the FieldPath will be the JSON field names (instead of the go field names) JSONNames bool // DeprecatedDoubleVisit activates the compatibility mode of the walker, where we end up visiting every struct field twice. // Ideally we can replace these instances over time. DeprecatedDoubleVisit bool }