reflext

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMapper = NewMapperFunc("sqlike", nil)

DefaultMapper :

Functions

func Deref

func Deref(t reflect.Type) reflect.Type

Deref : this is the replacement for reflect.Elem()

func FieldByIndexes

func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value

FieldByIndexes : get reflect.Value from struct by indexes. If the reflect.Value is nil, it will get initialized

func FieldByIndexesReadOnly

func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value

FieldByIndexesReadOnly : get reflect.Value from struct by indexes without initialized

func Indirect

func Indirect(v reflect.Value) reflect.Value

Indirect : this is the replacement for reflect.Indirect()

func IndirectInit

func IndirectInit(v reflect.Value) reflect.Value

IndirectInit : initialise reflect.Value till the deep level

func Init

func Init(v reflect.Value) reflect.Value

Init : initialise the first level of reflect.Value

func IsKind

func IsKind(t reflect.Type, k reflect.Kind) bool

IsKind : compare and check the respective reflect.Kind

func IsNull

func IsNull(v reflect.Value) bool

IsNull : determine the reflect.Value is null or not

func IsNullable

func IsNullable(t reflect.Type) bool

IsNullable : determine whether is nullable data type

func IsZero

func IsZero(v reflect.Value) bool

IsZero : determine is zero value 1. string => empty string 2. bool => false 3. function => nil 4. map => nil (uninitialized map) 5. slice => nil (uninitialized slice)

func Set

func Set(src, v reflect.Value)

Set :

func TypeOf

func TypeOf(i interface{}) reflect.Type

TypeOf : this is the replacement for reflect.TypeOf()

func ValueOf

func ValueOf(i interface{}) reflect.Value

ValueOf : this is the replacement for reflect.ValueOf()

func Zero

func Zero(t reflect.Type) (v reflect.Value)

Zero :

Types

type Fields

type Fields []StructFielder

Fields :

func (Fields) Len

func (x Fields) Len() int

func (Fields) Less

func (x Fields) Less(i, j int) bool

func (Fields) Swap

func (x Fields) Swap(i, j int)

type FormatFunc

type FormatFunc func(string) string

FormatFunc :

type MapFunc

type MapFunc func(StructFielder) (skip bool)

MapFunc :

type Mapper

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

Mapper :

func NewMapperFunc

func NewMapperFunc(tag string, fmtFunc FormatFunc) *Mapper

NewMapperFunc :

func (*Mapper) CodecByType

func (m *Mapper) CodecByType(t reflect.Type) Structer

CodecByType :

func (*Mapper) FieldByIndexes

func (m *Mapper) FieldByIndexes(v reflect.Value, idxs []int) reflect.Value

FieldByIndexes : get reflect.Value from struct by indexes. If the reflect.Value is nil, it will get initialized

func (*Mapper) FieldByIndexesReadOnly

func (m *Mapper) FieldByIndexesReadOnly(v reflect.Value, idxs []int) reflect.Value

FieldByIndexesReadOnly : get reflect.Value from struct by indexes without initialized

func (*Mapper) FieldByName

func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value

FieldByName : get reflect.Value from struct by field name

func (*Mapper) LookUpFieldByName

func (m *Mapper) LookUpFieldByName(v reflect.Value, name string) (reflect.Value, bool)

LookUpFieldByName : lookup reflect.Value from struct by field name

func (*Mapper) TraversalsByName

func (m *Mapper) TraversalsByName(t reflect.Type, names []string) (idxs [][]int)

TraversalsByName :

func (*Mapper) TraversalsByNameFunc

func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int)) (idxs [][]int)

TraversalsByNameFunc :

type Struct

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

Struct :

func (*Struct) Fields

func (s *Struct) Fields() []StructFielder

Fields :

func (*Struct) GetByTraversal

func (s *Struct) GetByTraversal(index []int) StructFielder

GetByTraversal :

func (*Struct) LookUpFieldByName added in v1.1.1

func (s *Struct) LookUpFieldByName(name string) (StructFielder, bool)

LookUpFieldByName :

func (*Struct) Properties

func (s *Struct) Properties() []StructFielder

Properties :

type StructField

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

StructField :

func (*StructField) Children

func (sf *StructField) Children() []StructFielder

Children :

func (*StructField) Index

func (sf *StructField) Index() []int

Index :

func (*StructField) IsEmbedded added in v1.1.1

func (sf *StructField) IsEmbedded() bool

IsEmbedded :

func (*StructField) IsNullable

func (sf *StructField) IsNullable() bool

IsNullable :

func (*StructField) Name

func (sf *StructField) Name() string

Name :

func (*StructField) Parent

func (sf *StructField) Parent() StructFielder

Parent :

func (*StructField) ParentByTraversal

func (sf *StructField) ParentByTraversal(cb func(StructFielder) bool) StructFielder

ParentByTraversal :

func (*StructField) Tag

func (sf *StructField) Tag() StructTag

Tag :

func (*StructField) Type

func (sf *StructField) Type() reflect.Type

Type :

type StructFielder added in v1.1.1

type StructFielder interface {
	// New name of struct field
	Name() string

	// reflect.Type of the field
	Type() reflect.Type

	// index position of the field
	Index() []int

	Tag() StructTag

	// if the field is struct, parent will not be nil
	// this will be the parent struct of current struct
	Parent() StructFielder

	ParentByTraversal(cb func(StructFielder) bool) StructFielder

	// if the field is struct, children will not be nil
	// this will be the fields of current struct
	Children() []StructFielder

	// determine the field is nullable
	IsNullable() bool

	// determine the field is embedded struct
	IsEmbedded() bool
}

StructFielder :

type StructMapper added in v1.0.2

type StructMapper interface {
	CodecByType(t reflect.Type) Structer
	FieldByName(v reflect.Value, name string) reflect.Value
	FieldByIndexes(v reflect.Value, idxs []int) reflect.Value
	FieldByIndexesReadOnly(v reflect.Value, idxs []int) reflect.Value
	LookUpFieldByName(v reflect.Value, name string) (reflect.Value, bool)
	TraversalsByName(t reflect.Type, names []string) (idxs [][]int)
	TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int)) (idxs [][]int)
}

StructMapper :

type StructTag

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

StructTag :

func (StructTag) Get

func (st StructTag) Get(key string) string

Get :

func (StructTag) LookUp

func (st StructTag) LookUp(key string) (val string, exist bool)

LookUp :

func (StructTag) Name

func (st StructTag) Name() string

Name :

func (StructTag) OriginalName

func (st StructTag) OriginalName() string

OriginalName :

type Structer added in v1.1.1

type Structer interface {
	Fields() []StructFielder
	Properties() []StructFielder
	LookUpFieldByName(name string) (StructFielder, bool)
	GetByTraversal(index []int) StructFielder
}

Structer :

type Zeroer added in v1.0.2

type Zeroer interface {
	IsZero() bool
}

Zeroer :

Jump to

Keyboard shortcuts

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