1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-04 10:47:20 +00:00

add a new x/reflex sub-package for reflection common functions - may be improved in the near future

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-03-06 17:11:56 +02:00
parent fc2f8f4776
commit 410e5eae83
7 changed files with 224 additions and 0 deletions

19
x/reflex/reflectx.go Normal file
View File

@@ -0,0 +1,19 @@
package reflex
import "reflect"
// IndirectType returns the value of a pointer-type "typ".
// If "IndirectType" is a pointer, array, chan, map or slice it returns its Elem,
// otherwise returns the "typ" as it is.
func IndirectType(typ reflect.Type) reflect.Type {
switch typ.Kind() {
case reflect.Ptr, reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
return typ.Elem()
}
return typ
}
// IndirectValue returns the element type (e.g. if pointer of *User it will return the User type).
func IndirectValue(val reflect.Value) reflect.Value {
return reflect.Indirect(val)
}