treflect

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone added in v1.0.5

func Clone(v interface{}) interface{}

Clone does a deep copy of the given value. Please note that field have to be public in order to be copied. Private fields will be ignored.

func Float32

func Float32(v interface{}) (float32, bool)

Float32 converts any number type to an float32. The second parameter is returned as false if a non-number type was given.

func Float64

func Float64(v interface{}) (float64, bool)

Float64 converts any number type to an float64. The second parameter is returned as false if a non-number type was given.

func GetMissingMethods

func GetMissingMethods(objType reflect.Type, ifaceType reflect.Type) (float32, []string)

GetMissingMethods checks if a given object implements all methods of a given interface. It returns the interface coverage [0..1] as well as an array of error messages. If the interface is correctly implemented the coverage is 1 and the error message array is empty.

func Int64

func Int64(v interface{}) (int64, bool)

Int64 converts any signed number type to an int64. The second parameter is returned as false if a non-number type was given.

func RemovePtrFromType

func RemovePtrFromType(t interface{}) reflect.Type

RemovePtrFromType will return the type of t and strips away any pointer(s) in front of the actual type.

func RemovePtrFromValue

func RemovePtrFromValue(t interface{}) reflect.Value

RemovePtrFromValue will return the value of t and strips away any pointer(s) in front of the actual type.

func SetMemberByIndex

func SetMemberByIndex(ptrToStruct interface{}, idx int, data interface{})

SetMemberByIndex sets member idx of the given pointer-to-struct to the data passed to this function. The member may be private, too.

func SetMemberByName

func SetMemberByName(ptrToStruct interface{}, name string, data interface{})

SetMemberByName sets member name of the given pointer-to-struct to the data passed to this function. The member may be private, too.

func SetValue

func SetValue(member reflect.Value, data interface{})

SetValue sets an addressable value to the data passed to this function. In contrast to golangs reflect package this will also work with private variables. Please note that this function may not support all types, yet.

func Uint64

func Uint64(v interface{}) (uint64, bool)

Uint64 converts any unsigned number type to an uint64. The second parameter is returned as false if a non-number type was given.

func UnsafeCopy

func UnsafeCopy(dst, src interface{})

UnsafeCopy will copy data from src to dst while ignoring type information. Both types need to be of the same size and dst and src have to be pointers. UnsafeCopy will panic if these requirements are not met.

func UnsafeCopyValue

func UnsafeCopyValue(dstValue reflect.Value, srcValue reflect.Value)

UnsafeCopyValue will copy data from src to dst while ignoring type information. Both types need to be of the same size or this function will panic. Also both types must support dereferencing via reflect.Elem()

Types

type TypeRegistry

type TypeRegistry struct {
	// contains filtered or unexported fields
}

TypeRegistry is a name to type registry used to create objects by name.

func NewTypeRegistry

func NewTypeRegistry() TypeRegistry

NewTypeRegistry creates a new TypeRegistry. Note that there is a global type registry available in the main tgo package (tgo.TypeRegistry).

func (TypeRegistry) GetRegistered

func (registry TypeRegistry) GetRegistered(packageName string) []string

GetRegistered returns the names of all registered types for a given package

func (TypeRegistry) GetTypeOf

func (registry TypeRegistry) GetTypeOf(typeName string) reflect.Type

GetTypeOf returns only the type asscociated with the given name. If the name is not registered, nil is returned. The type returned will be a pointer type.

func (TypeRegistry) IsTypeRegistered

func (registry TypeRegistry) IsTypeRegistered(typeName string) bool

IsTypeRegistered returns true if a type is registered to this registry. Note that GetTypeOf can do the same thing by checking for nil but also returns the type, so in many cases you will want to call this function.

func (TypeRegistry) New

func (registry TypeRegistry) New(typeName string) (interface{}, error)

New creates an uninitialized object by class name. The class name has to be "package.class" or "package/subpackage.class". The gollum package is omitted from the package path.

func (TypeRegistry) Register

func (registry TypeRegistry) Register(typeInstance interface{})

Register a plugin to the TypeRegistry by passing an uninitialized object.

func (TypeRegistry) RegisterWithDepth

func (registry TypeRegistry) RegisterWithDepth(typeInstance interface{}, depth int)

RegisterWithDepth to register a plugin to the TypeRegistry by passing an uninitialized object.

Jump to

Keyboard shortcuts

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