reflector

package module
v0.0.13-dev Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 7 Imported by: 4

README

Reflector Logo

Go Report Card CircleCI

Reflector

Reflector is a reflection library written in Go, which provides an abstraction for built-in reflection API in GoLang. Unlike the built-in reflection API, it is easy to use and understand.

Stargazers

Forkers

License

Reflector is released under MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsArray

func IsArray(typ Type) bool

func IsBasic

func IsBasic(typ Type) bool

func IsBoolean

func IsBoolean(typ Type) bool

func IsChan

func IsChan(typ Type) bool

func IsComplex

func IsComplex(typ Type) bool

func IsCustom

func IsCustom(typ Type) bool

func IsFloat

func IsFloat(typ Type) bool

func IsFunction

func IsFunction(typ Type) bool

func IsInteger

func IsInteger(typ Type) bool

func IsInterface

func IsInterface(typ Type) bool

func IsMap

func IsMap(typ Type) bool

func IsNumber

func IsNumber(typ Type) bool

func IsPointer

func IsPointer(typ Type) bool

func IsSignedInteger

func IsSignedInteger(typ Type) bool

func IsSlice

func IsSlice(typ Type) bool

func IsString

func IsString(typ Type) bool

func IsStruct

func IsStruct(typ Type) bool

func IsUnsignedInteger

func IsUnsignedInteger(typ Type) bool

Types

type Array

type Array interface {
	Type
	Elem() Type
	Len() int
	Get(index int) (any, error)
	Set(index int, val any) error
	Slice(low, high int) (any, error)
	Copy(dst any) (int, error)
}

func ToArray

func ToArray(typ Type) Array

type BitSize

type BitSize int
const (
	BitSize8   BitSize = 8
	BitSize16  BitSize = 16
	BitSize32  BitSize = 32
	BitSize64  BitSize = 64
	BitSize128 BitSize = 128
)

type Boolean

type Boolean interface {
	Type
	BooleanValue() (bool, error)
	SetBooleanValue(val bool) error
}

func ToBoolean

func ToBoolean(typ Type) Boolean

type Chan

type Chan interface {
	Type
	Direction() ChanDirection
	Elem() Type
	Cap() (int, error)
	Send(value any) error
	Receive() (any, error)
	TrySend(value any) error
	TryReceive() (any, error)
}

func ToChan

func ToChan(typ Type) Chan

type ChanDirection

type ChanDirection int
const (
	RECEIVE ChanDirection    = 1 << iota // <-chan
	SEND                                 // chan<-
	BOTH    = RECEIVE | SEND             // chan
)

type Complex

type Complex interface {
	Type
	BitSize() BitSize
	ComplexValue() (complex128, error)
	SetComplexValue(v complex128) error
	ImaginaryData() (float64, error)
	RealData() (float64, error)
	SetImaginaryData(val float64) error
	SetRealData(val float64) error
}

func ToComplex

func ToComplex(typ Type) Complex

type Custom

type Custom interface {
	Type
	Underlying() Type
	Methods() []Function
	NumMethod() int
	Implements(i Interface) bool
}

func ToCustom

func ToCustom(typ Type) Custom

type Entry

type Entry interface {
	Key() any
	Value() any
}

type Field

type Field interface {
	Name() string
	Index() int
	IsExported() bool
	IsAnonymous() bool
	Type() Type
	CanSet() bool
	Value() (any, error)
	SetValue(value any) error
	Tags() Tags
	ReflectStructField() reflect.StructField
}

type Float

type Float interface {
	Type
	BitSize() BitSize
	FloatValue() (float64, error)
	SetFloatValue(v float64) error
	Overflow(v float64) bool
}

func ToFloat

func ToFloat(typ Type) Float

type Function

type Function interface {
	Type
	IsExported() bool
	Parameters() []Type
	NumParameter() int
	Results() []Type
	NumResult() int
	IsVariadic() bool
	Invoke(args ...any) ([]any, error)
}

func ToFunction

func ToFunction(typ Type) Function

type Interface

type Interface interface {
	Type
	Underlying() Type
	Methods() []Method
	NumMethod() int
}

func ToInterface

func ToInterface(typ Type) Interface

type Map

type Map interface {
	Type
	Key() Type
	Elem() Type
	Len() (int, error)
	Contains(key any) (bool, error)
	Get(key any) (any, error)
	Put(key any, val any) error
	Delete(key any) error
	Clear() error
	KeySet() ([]any, error)
	ValueSet() ([]any, error)
	EntrySet() ([]Entry, error)
}

func ToMap

func ToMap(typ Type) Map

type Method

type Method interface {
	Type
	IsExported() bool
	Receiver() Type
	Parameters() []Type
	NumParameter() int
	Results() []Type
	NumResult() int
	IsVariadic() bool
	Invoke(args ...any) ([]any, error)
	ReflectMethod() reflect.Method
}

type Pointer

type Pointer interface {
	Type
	Elem() Type
}

func ToPointer

func ToPointer(typ Type) Pointer

type SignedInteger

type SignedInteger interface {
	Type
	BitSize() BitSize
	IntegerValue() (int64, error)
	SetIntegerValue(v int64) error
	Overflow(v int64) bool
}

func ToSignedInteger

func ToSignedInteger(typ Type) SignedInteger

type Slice

type Slice interface {
	Type
	Elem() Type
	Len() (int, error)
	Cap() (int, error)
	Get(index int) (any, error)
	Set(index int, val any) error
	Append(values ...any) (any, error)
	Slice(low, high int) (any, error)
	Copy(dst any) (int, error)
}

func ToSlice

func ToSlice(typ Type) Slice

type String

type String interface {
	Type
	StringValue() (string, error)
	SetStringValue(val string) error
}

func ToString

func ToString(typ Type) String

type Struct

type Struct interface {
	Type
	Fields() []Field
	Field(index int) (Field, bool)
	FieldByName(name string) (Field, bool)
	NumField() int
	Methods() []Method
	Method(index int) (Method, bool)
	MethodByName(name string) (Method, bool)
	NumMethod() int
	Implements(i Interface) bool
	Embeds(another Type) bool
}

func ToStruct

func ToStruct(typ Type) Struct

type Tag

type Tag interface {
	Name() string
	Value() string
}

type Tags

type Tags []Tag

func (Tags) Contains

func (t Tags) Contains(name string) bool

func (Tags) Find

func (t Tags) Find(name string) (Tag, bool)

type Type

type Type interface {
	Name() string
	PackageName() string
	PackagePath() string
	CanSet() bool
	HasValue() bool
	Value() (any, error)
	SetValue(val any) error
	Parent() Type
	ReflectType() reflect.Type
	ReflectValue() *reflect.Value
	Compare(another Type) bool
	IsInstantiable() bool
	Instantiate() (Value, error)
	CanConvert(another Type) bool
	Convert(another Type) (Value, error)
}

func TypeOf

func TypeOf[T any]() Type

func TypeOfAny

func TypeOfAny[T any](obj T) Type

type UnsignedInteger

type UnsignedInteger interface {
	Type
	BitSize() BitSize
	IntegerValue() (uint64, error)
	SetIntegerValue(v uint64) error
	Overflow(v uint64) bool
}

func ToUnsignedInteger

func ToUnsignedInteger(typ Type) UnsignedInteger

type Value

type Value interface {
	Val() any
	Elem() any
}

Jump to

Keyboard shortcuts

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