types

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCantSet      = errors.New("can't set value (you might need to pass a pointer)")
	ErrInvalidValue = errors.New("invalid value")
)

Functions

func Convert

func Convert(in interface{}, out interface{}) error

Convert converts the in parameter to the out parameter, which must be a non-nil pointer, usually to a different type than in. Supported parameters type are u?int(8|16|32|64)?, float(32|64) and string.

func Equal

func Equal(obj1, obj2 interface{}) bool

Equal is a shortcut for reflect.DeepEqual.

func IsFloat

func IsFloat(typ reflect.Type) bool

IsFloat returns true iff typ is any of the float types.

func IsInt

func IsInt(typ reflect.Type) bool

IsInt returns true iff typ is any of the int types.

func IsNumeric

func IsNumeric(typ reflect.Type) bool

IsNumeric returns true iff the type is one of the int, uint, float or complex types.

func IsTrue

func IsTrue(value interface{}) (truth, ok bool)

IsTrue returns whether the value is 'true', in the sense of not the zero of its type, and whether the value has a meaningful truth value. This function is a copy of the one found in text/template

func IsTrueVal

func IsTrueVal(val reflect.Value) (truth, ok bool)

IsTrueVal works like IsTrue, but accepts a reflect.Value rather than an interface{}.

func IsUint

func IsUint(typ reflect.Type) bool

IsUint returns true iff typ is any of the uint types.

func SettableValue

func SettableValue(val interface{}) (reflect.Value, error)

func SortValues

func SortValues(v []reflect.Value) error

SortValues sorts the given slice of reflect.Value, if possible. If the slice can't be sorted, an error is returned.

func ToFloat

func ToFloat(val interface{}) (float64, error)

ToFloat tries to convert its argument to a 64-bit float. It will convert bool, int, uint and its variants, floats and even strings if it can parse them.

func ToInt

func ToInt(val interface{}) (int, error)

ToInt tries to convert its argument to an integer. It will convert bool, int, uint and its variants, floats and even strings if it can parse them.

func ToInt64

func ToInt64(val interface{}) (int64, error)

ToInt64 tries to convert its argument to an int64. It will convert bool, int, uint and its variants, floats and even strings if it can parse them.

func ToString

func ToString(val interface{}) string

ToString transforms the given value into a string. If the value is a nil pointer or a nil interface, it returns the empty string.

func ToUint

func ToUint(val interface{}) (uint, error)

ToUint tries to convert its argument to an unsigned integer. It will convert bool, int, uint and its variants, floats and even strings if it can parse them.

func ToUint64

func ToUint64(val interface{}) (uint64, error)

ToUint64 tries to convert its argument to an unsigned integer. It will convert bool, int, uint and its variants, floats and even strings if it can parse them.

Types

type KindGroup

type KindGroup uint

KindGroup groups different reflect Kinds which support the same set of operations

const (
	// Invalid includes reflect.Invalid
	Invalid KindGroup = iota
	// Bool includes reflect.Bool
	Bool
	// Int includes reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32 and reflect.Int64
	Int
	// Uint includes reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32 and reflect.Uint64
	Uint
	// Uintptr includes reflect.Uintptr
	Uintptr
	// Float includes reflect.Float32 and reflect.Float64
	Float
	// Complex includes reflect.Complex64 and reflect.Complex128
	Complex
	// Array includes reflect.Array
	Array
	// Chan includes reflect.Chan
	Chan
	// Func includes reflect.Func
	Func
	// Interface includes reflect.Interface
	Interface
	// Map includes reflect.Map
	Map
	// Ptr includes reflect.Ptr
	Ptr
	// Slice includes reflect.Slice
	Slice
	// String includes reflect.String
	String
	// Struct includes reflect.Struct
	Struct
	// UnsafePointer includes reflect.UnsafePointer
	UnsafePointer
)

func Kind

func Kind(k reflect.Kind) KindGroup

Kind returns the KindGroup for the given reflect.Kind.

Jump to

Keyboard shortcuts

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