reflectutils

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2020 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SkipReflection = errors.New("skip this value")

Functions

func BuildTypeName

func BuildTypeName(t reflect.Type) string

func FormatValue

func FormatValue(value interface{}) string

FormatValue returns a string representing the value

func InvokeMethod

func InvokeMethod(target interface{}, name string, args ...interface{}) ([]reflect.Value, error)

InvokeMethod calls the specified method by reflection

func IsMethodNotFound

func IsMethodNotFound(err error) bool

func IsPrimitiveValue

func IsPrimitiveValue(v reflect.Value) bool

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

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

func ReflectRecursive

func ReflectRecursive(v reflect.Value, visitor visitorFunc) 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

func ValueAsString(value reflect.Value) string

ValueAsString returns a human-readable string representation of the passed value

Types

type MethodNotFoundError

type MethodNotFoundError struct {
	Name   string
	Target interface{}
}

func (*MethodNotFoundError) Error

func (e *MethodNotFoundError) Error() string

type Printer

type Printer func(o interface{}) (string, bool)

Printer is a custom printer function, so we can add special display for objects (without introducing a package dependency)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL