ref

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Niltyp = reflect.TypeOf((*string)(nil)) //nolint:gochecknoglobals //i know that
View Source
var StringType = reflect.TypeOf((*string)(nil)).Elem() //nolint:gochecknoglobals //i know that

Functions

func ArrayIsZero

func ArrayIsZero(v reflect.Value) bool

func ArrayIsZerov

func ArrayIsZerov(v *reflect.Value) bool

func CanConvert

func CanConvert(v *reflect.Value, t reflect.Type) bool

CanConvert reports whether the value v can be converted to type t. If v.CanConvert(t) returns true then v.Convert(t) will not panic.

func CanConvertHelper

func CanConvertHelper(v reflect.Value, t reflect.Type) bool

CanConvertHelper is a shorthand of CanConvert.

func HasStringer

func HasStringer(v *reflect.Value) bool

func IsExported

func IsExported(f *reflect.StructField) bool

IsExported reports whether the field is exported.

func IsMap

func IsMap(v any) bool

IsMap tests if a given 'v' is a map (or pointer of map, ...)

func IsNil

func IsNil(v reflect.Value) bool

IsNil for go1.12+, the difference is it never panic on unavailable kinds. see also reflect.IsNil.

func IsNilT

func IsNilT[T any](id T) (ret bool)

IsNilT for go1.18+

func IsNilv

func IsNilv(v *reflect.Value) bool

IsNilv for go1.12+, the difference is it never panic on unavailable kinds. see also reflect.IsNil.

func IsNumComplexKind

func IsNumComplexKind(k reflect.Kind) bool

func IsNumFloatKind

func IsNumFloatKind(k reflect.Kind) bool

func IsNumIntegerKind

func IsNumIntegerKind(k reflect.Kind) bool

func IsNumIntegerType

func IsNumIntegerType(t reflect.Type) bool

func IsNumSIntegerKind

func IsNumSIntegerKind(k reflect.Kind) bool

func IsNumUIntegerKind

func IsNumUIntegerKind(k reflect.Kind) bool

func IsNumeric

func IsNumeric(v any) bool

IsNumeric tests if a given 'v' is a number (int, uint, float, ...)

func IsNumericKind

func IsNumericKind(k reflect.Kind) bool

func IsNumericType

func IsNumericType(t reflect.Type) bool

func IsSlice

func IsSlice(v any) bool

IsSlice tests if a given 'v' is a slice ([]int, []uint, []string, ...)

func IsValid

func IsValid(v reflect.Value) bool

func IsValidv

func IsValidv(v *reflect.Value) bool

func IsZero

func IsZero(v reflect.Value) (ret bool)

IsZero for go1.12+, the difference is it never panic on unavailable kinds. see also reflect.IsZero.

func IsZerov

func IsZerov(v *reflect.Value) (ret bool)

IsZerov for go1.12+, the difference is it never panic on unavailable kinds. see also reflect.IsZero.

func Iserrortype

func Iserrortype(typ reflect.Type) bool

func KindIs

func KindIs(k reflect.Kind, list ...reflect.Kind) bool

func Rdecode

func Rdecode(reflectValue reflect.Value) (ret, prev reflect.Value)

Rdecode decodes an interface{} or a pointer to something to its underlying data type.

Suppose we have an interface{} pointer Value which stored a pointer to an integer, Rdecode will extract or retrieve the Value of that integer.

See our TestRdecode() in ref_test.go

var b = 11
var i interface{} = &b
var v = reflect.ValueOf(&i)
var n = Rdecode(v)
println(n.Type())    // = int

`prev` returns the previous Value before we arrived at the final `ret` Value. In another word, the value of `prev` Value is a pointer which points to the value of `ret` Value. Or, it's a interface{} wrapped about `ret`.

A interface{} will be unboxed to its underlying datatype after Rdecode invoked.

func Rdecodesimple

func Rdecodesimple(reflectValue reflect.Value) (ret reflect.Value)

Rdecodesimple is a shortcut to Rdecode without `prev` returned.

func Rdecodetype

func Rdecodetype(reflectType reflect.Type) (ret, prev reflect.Type)

Rdecodetype try to strip off ptr and interface{} from a type.

It might not work properly on some cases because interface{} cannot be stripped with calling typ.Elem().

In this case, use rdecodesimple(value).Type() instead of Rdecodetypesimple(value.Type()).

func Rdecodetypesimple

func Rdecodetypesimple(reflectType reflect.Type) (ret reflect.Type)

Rdecodetypesimple try to strip off ptr and interface{} from a type.

It might not work properly on some cases because interface{} cannot be stripped with calling typ.Elem(). For this case, use Rdecodesimple(value).Type() instead of Rdecodetypesimple(value.Type()).

func Rindirect

func Rindirect(reflectValue reflect.Value) reflect.Value

func RindirectType

func RindirectType(reflectType reflect.Type) reflect.Type

func Rskip

func Rskip(reflectValue reflect.Value, kinds ...reflect.Kind) (ret, prev reflect.Value)

func Rskiptype

func Rskiptype(reflectType reflect.Type, kinds ...reflect.Kind) (ret, prev reflect.Type)

func Rwant

func Rwant(reflectValue reflect.Value, kinds ...reflect.Kind) reflect.Value

func SliceAppend

func SliceAppend(vv ...any) (ret any)

SliceAppend combines all given slices ('vv') as one result slice. That is, SliceAppend([]int{1,2}, []int{2,3}) will return []int{1,2,2,3}.

func SliceMerge

func SliceMerge(vv ...any) (ret any)

SliceMerge merge all given slices ('vv') as one result slice. That is, SliceAppend([]int{1,2}, []int{2,3}) will return []int{1,2,3}.

func StructIsZero

func StructIsZero(v reflect.Value) bool

func StructIsZerov

func StructIsZerov(v *reflect.Value) bool

func Typfmt

func Typfmt(t reflect.Type) string

func Typfmtptr

func Typfmtptr(t *reflect.Type) string

func Typfmtv

func Typfmtv(v *reflect.Value) string

func Typfmtvlite

func Typfmtvlite(v *reflect.Value) string

func Valfmt

func Valfmt(v *reflect.Value) string

func ValfmtPure

func ValfmtPure(v *reflect.Value) string

func Valfmtptr

func Valfmtptr(v *reflect.Value) string

Valfmtptr will step into a ptr value at first, then Valfmt.

func ValfmtptrPure

func ValfmtptrPure(v *reflect.Value) string

ValfmtptrPure will step into a ptr value at first, then Valfmt.

func Valfmtv

func Valfmtv(v reflect.Value) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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