Reflection

Index

All Reflection functions

Name Function header Example Result Description Errorhandling
kindIs func(src interface{}, target string) bool [[ $result := toString (kindIs (int "12345") "int") ]] $result = true will test the value and send back the object type and returns true also, if interface is a pointer to the type
kindOf func(src interface{}) string [[ $result := kindOf (toByte "12345 This is a test string") ]] $result = slice returns the kind of an object
typeIs func(src interface{}, target string) bool [[ $result := toString (typeIs "int" "string") ]] $result = true is like kindIs, but for types: typeIs “*io.Buffer” $myVal.
typeIsLike func(src interface{}, target string) bool [[ $result := typeIsLike (typeIs (int "12345") "int") ]] $result = true works as typeIs, except that it also dereferences pointers.
typeOf func(src interface{}) string [[ typeOf (toByte "12345 This is a test string") ]] $result = []uint8 returns the underlying type of a value: typeOf $foo and returns true also, if interface is a pointer to the type

kindIs

func(src interface{}, target string) bool

The kindIs function will test the value and send back the object type.

Examples


[[ $result := toString (kindIs "int" "12345") ]]
$result = false

[[ $result := toString (kindIs (int "12345")  "int") ]]
$result = true

[[ $result := toString (kindIs "int" "string") ]]
$result = true

[[ $result := toString (kindIs (int64 "12345")  "int64") ]]
$result = true

[[ $result := toString (kindIs (int "12345")  "int64") ]]
$result = false

kindOf

func(src interface{}) string

The kindOf function returns the kind of an object.

Examples


[[ $result := kindOf "This is a test string" ]]
$result = string

[[ $result := kindOf (int "12345") ]]
$result = int

[[ $result := kindOf (int64 "12345") ]]
$result = int64

[[ $result := kindOf (atoi "12345") ]]
$result = int

[[ $result := kindOf (toByte "12345 This is a test string") ]]
$result = slice

[[ $result := kindOf (date 1638860002 "02.01.2006") ]]
$result = string

[[ $result := kindOf (split "A,B,C" ",")]]
$result = slice

typeIs

func(src interface{}, target string) bool

The typeIs function is like kindIs, but for types: typeIs “*io.Buffer” $myVal.

Examples


[[ $result := toString (typeIs "int" "12345") ]]
$result = false

[[ $result := toString (typeIs (int "12345")  "int") ]]
$result = true

[[ $result := toString (typeIs "int" "string") ]]
$result = true

[[ $result := toString (typeIs (int64 "12345")  "int64") ]]
$result = true

[[ $result := toString (typeIs (int "12345")  "int64") ]]
$result = false

typeIsLike

func(src interface{}, target string) bool

The typeIsLike function works as typeIs, except that it also dereferences pointers.

Example with typeIsLike

Examples


[[ $result := typeIsLike (typeIs "int" "12345") ]]
$result = false

[[ $result := typeIsLike (typeIs (int "12345")  "int") ]]
$result = true

[[ $result := typeIsLike (typeIs "int" "string") ]]
$result = true

[[ $result := typeIsLike (typeIs (int64 "12345")  "int64") ]]
$result = true

[[ $result := typeIsLike (typeIs (int "12345")  "int64") ]]
$result = false

typeOf

func(src interface{}) string

The typeOf function returns the underlying type of a value: typeOf $foo.

Examples


[[ $result := typeOf "This is a test string" ]]
$result = string

[[ $result := typeOf (int "12345") ]]
$result = int

[[ $result := typeOf (int64 "12345") ]]
$result = int64

[[ $result := typeOf (atoi "12345") ]]
$result = int

[[ $result := typeOf (toByte "12345 This is a test string") ]]
$result = []uint8

[[ $result := typeOf (date 1638860002 "02.01.2006") ]]
$result = string

[[ $result := typeOf (split "A,B,C" ",")]]
$result = []string