mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
| datasource | package | from | to | | ---------- | ------------------------- | ------- | ------- | | go | github.com/expr-lang/expr | v1.17.6 | v1.17.7 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
57 lines
848 B
Go
57 lines
848 B
Go
package deref
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
func Interface(p any) any {
|
|
if p == nil {
|
|
return nil
|
|
}
|
|
|
|
v := reflect.ValueOf(p)
|
|
|
|
for v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface {
|
|
if v.IsNil() {
|
|
return nil
|
|
}
|
|
v = v.Elem()
|
|
}
|
|
|
|
if v.IsValid() {
|
|
return v.Interface()
|
|
}
|
|
|
|
panic(fmt.Sprintf("cannot dereference %v", p))
|
|
}
|
|
|
|
func Type(t reflect.Type) reflect.Type {
|
|
if t == nil {
|
|
return nil
|
|
}
|
|
for t.Kind() == reflect.Ptr {
|
|
t = t.Elem()
|
|
}
|
|
return t
|
|
}
|
|
|
|
func Value(v reflect.Value) reflect.Value {
|
|
for v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface {
|
|
if v.IsNil() {
|
|
return v
|
|
}
|
|
v = v.Elem()
|
|
}
|
|
return v
|
|
}
|
|
|
|
func TypeKind(t reflect.Type, k reflect.Kind) (_ reflect.Type, _ reflect.Kind, changed bool) {
|
|
for k == reflect.Pointer {
|
|
changed = true
|
|
t = t.Elem()
|
|
k = t.Kind()
|
|
}
|
|
return t, k, changed
|
|
}
|