reflection

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package reflection uses reflection to provide dynamic functionalities.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNameNotFound is returned when a lookup is performed with a
	// non-bound name.
	ErrNameNotFound = errors.New("name not bound to a value")

	// ErrNotCallable is returned when a Call is attempted on a non-
	// callable value.
	ErrNotCallable = errors.New("value is not callable")

	// ErrConversionImpossible is returned when the Value type cannot be
	// converted to the expected type.
	ErrConversionImpossible = errors.New("cannot be converted")

	// ErrInvalidNumberOfArgs is returned when a function call is attempted
	// with invalid number of arguments.
	ErrInvalidNumberOfArgs = errors.New("invalid number of arguments")
)

Functions

func Call

func Call(callable interface{}, args ...interface{}) (interface{}, error)

Call will execute a callable with given args. If the value bound to the name is not a callable, ErrNotCallable will be returned.

Types

type Value

type Value struct {
	RVal reflect.Value
}

Value represents every value in parens.

func NewValue

func NewValue(v interface{}) Value

NewValue creates a reflection wrapper around given value.

func (*Value) To

func (val *Value) To(kind reflect.Kind) (interface{}, error)

To converts the value to requested kind if possible.

func (*Value) ToBool

func (val *Value) ToBool() (bool, error)

ToBool attempts converting the value to bool.

func (*Value) ToFloat64

func (val *Value) ToFloat64() (float64, error)

ToFloat64 attempts converting the value to float64.

func (*Value) ToInt64

func (val *Value) ToInt64() (int64, error)

ToInt64 attempts converting the value to int64.

func (*Value) ToString

func (val *Value) ToString() (string, error)

ToString attempts converting the value to bool.

Jump to

Keyboard shortcuts

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