Help us shape the future of Go! Take the 2026 Go Developer Survey

reflectutils

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

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