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:
19
x/reflex/reflectx.go
Normal file
19
x/reflex/reflectx.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user