reflect

package module
v0.0.0-...-762e8fb Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2018 License: MIT Imports: 4 Imported by: 2

README

reflect

Build Status

Just a wrapper around reflect.

Type conversions

It could do simple type conversions for you:

$ go run ./examples/type-conversion/type-conversion.go
Convert []int to []string
([]string) (len=10 cap=10) {
 (string) (len=1) "1",
 (string) (len=1) "2",
 (string) (len=1) "3",
 (string) (len=1) "4",
 (string) (len=1) "5",
 (string) (len=1) "6",
 (string) (len=1) "7",
 (string) (len=1) "8",
 (string) (len=1) "9",
 (string) (len=1) "0"
}
(interface {}) <nil>
Convert map[int]string to map[string]int
(map[string]int) (len=10) {
 (string) (len=1) "8": (int) 8,
 (string) (len=1) "3": (int) 3,
 (string) (len=1) "5": (int) 5,
 (string) (len=1) "6": (int) 6,
 (string) (len=1) "7": (int) 7,
 (string) (len=1) "4": (int) 4,
 (string) (len=1) "9": (int) 9,
 (string) (len=1) "0": (int) 0,
 (string) (len=1) "1": (int) 1,
 (string) (len=1) "2": (int) 2
}
(interface {}) <nil>

Documentation

Index

Constants

View Source
const (
	Invalid       = reflect.Invalid
	Bool          = reflect.Bool
	Int           = reflect.Int
	Int8          = reflect.Int8
	Int16         = reflect.Int16
	Int32         = reflect.Int32
	Int64         = reflect.Int64
	Uint          = reflect.Uint
	Uint8         = reflect.Uint8
	Uint16        = reflect.Uint16
	Uint32        = reflect.Uint32
	Uint64        = reflect.Uint64
	Uintptr       = reflect.Uintptr
	Float32       = reflect.Float32
	Float64       = reflect.Float64
	Complex64     = reflect.Complex64
	Complex128    = reflect.Complex128
	Array         = reflect.Array
	Chan          = reflect.Chan
	Func          = reflect.Func
	Interface     = reflect.Interface
	Map           = reflect.Map
	Ptr           = reflect.Ptr
	Slice         = reflect.Slice
	String        = reflect.String
	Struct        = reflect.Struct
	UnsafePointer = reflect.UnsafePointer
)

Variables

View Source
var (
	Types = []Type{
		TypeBool,
		TypeInt,
		TypeInt8,
		TypeInt16,
		TypeInt32,
		TypeInt64,
		TypeUint,
		TypeUint8,
		TypeUint16,
		TypeUint32,
		TypeUint64,
		TypeFloat32,
		TypeFloat64,
		TypeComplex64,
		TypeComplex128,
		TypeUintptr,
		TypeString,
	}

	TypeInvalid    = Type(nil)
	TypeBool       = reflect.TypeOf(false)
	TypeInt        = reflect.TypeOf(int(0))
	TypeInt8       = reflect.TypeOf(int8(0))
	TypeInt16      = reflect.TypeOf(int16(0))
	TypeInt32      = reflect.TypeOf(int32(0))
	TypeInt64      = reflect.TypeOf(int64(0))
	TypeUint       = reflect.TypeOf(uint(0))
	TypeUint8      = reflect.TypeOf(uint8(0))
	TypeUint16     = reflect.TypeOf(uint16(0))
	TypeUint32     = reflect.TypeOf(uint32(0))
	TypeUint64     = reflect.TypeOf(uint64(0))
	TypeFloat32    = reflect.TypeOf(float32(0))
	TypeFloat64    = reflect.TypeOf(float64(0))
	TypeComplex64  = reflect.TypeOf(complex64(0))
	TypeComplex128 = reflect.TypeOf(complex128(0))
	TypeUintptr    = reflect.TypeOf(uintptr(0))
	TypeString     = reflect.TypeOf(string(""))
)
View Source
var (
	TypeOf = reflect.TypeOf
)
View Source
var (
	ValueOf = reflect.ValueOf
)

Functions

func ConvertToBool

func ConvertToBool(vv interface{}) (bool, error)

func ConvertToComplex64

func ConvertToComplex64(vv interface{}) (complex64, error)

func ConvertToComplex128

func ConvertToComplex128(vv interface{}) (complex128, error)

func ConvertToFloat32

func ConvertToFloat32(vv interface{}) (float32, error)

func ConvertToFloat64

func ConvertToFloat64(vv interface{}) (float64, error)

func ConvertToInt

func ConvertToInt(vv interface{}) (int, error)

func ConvertToInt8

func ConvertToInt8(vv interface{}) (int8, error)

func ConvertToInt16

func ConvertToInt16(vv interface{}) (int16, error)

func ConvertToInt32

func ConvertToInt32(vv interface{}) (int32, error)

func ConvertToInt64

func ConvertToInt64(vv interface{}) (int64, error)

func ConvertToString

func ConvertToString(vv interface{}) (string, error)

func ConvertToType

func ConvertToType(v interface{}, t Type) (interface{}, error)

func ConvertToUint

func ConvertToUint(vv interface{}) (uint, error)

func ConvertToUint8

func ConvertToUint8(vv interface{}) (uint8, error)

func ConvertToUint16

func ConvertToUint16(vv interface{}) (uint16, error)

func ConvertToUint32

func ConvertToUint32(vv interface{}) (uint32, error)

func ConvertToUint64

func ConvertToUint64(vv interface{}) (uint64, error)

func Indirect

func Indirect(v interface{}) interface{}

Types

type ErrCanNotAssertType

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

func NewErrCanNotAssertType

func NewErrCanNotAssertType(value interface{}, to Type, reason ...string) ErrCanNotAssertType

func (ErrCanNotAssertType) Error

func (e ErrCanNotAssertType) Error() string

type ErrCanNotConvertType

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

func NewErrCanNotConvertType

func NewErrCanNotConvertType(value interface{}, from Type, to Type, reason ...string) ErrCanNotConvertType

func (ErrCanNotConvertType) Error

func (e ErrCanNotConvertType) Error() string

type ErrCanNotParseType

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

func NewErrCanNotParseType

func NewErrCanNotParseType(t string, reason string) ErrCanNotParseType

func (ErrCanNotParseType) Error

func (e ErrCanNotParseType) Error() string

type ErrUnknownType

type ErrUnknownType struct {
	Value interface{}
}

func NewErrUnknownType

func NewErrUnknownType(v interface{}) *ErrUnknownType

func (*ErrUnknownType) Error

func (e *ErrUnknownType) Error() string

type ErrWrongArgumentsQuantity

type ErrWrongArgumentsQuantity struct {
	Want int
	Got  int
}

func NewErrWrongArgumentsQuantity

func NewErrWrongArgumentsQuantity(want int, got int) *ErrWrongArgumentsQuantity

func (*ErrWrongArgumentsQuantity) Error

func (e *ErrWrongArgumentsQuantity) Error() string

type ErrWrongKind

type ErrWrongKind struct {
	Want Kind
	Got  Kind
}

func NewErrWrongKind

func NewErrWrongKind(want Kind, got Kind) *ErrWrongKind

func (*ErrWrongKind) Error

func (e *ErrWrongKind) Error() string

type Kind

type Kind = reflect.Kind

type Type

type Type = reflect.Type

func IndirectType

func IndirectType(reflectType Type) Type

func ParseType

func ParseType(p string) (Type, error)

type Value

type Value = reflect.Value

func IndirectValue

func IndirectValue(reflectValue Value) Value

Directories

Path Synopsis
examples
type-conversion command
tools
type-vars command

Jump to

Keyboard shortcuts

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