mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-09 09:35:03 +09:00
Fix nil interface issue
This commit is contained in:
parent
b04a48144d
commit
fbf22655fe
3 changed files with 33 additions and 1 deletions
19
util/reflection/reflect.go
Normal file
19
util/reflection/reflect.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package reflection
|
||||
|
||||
import "reflect"
|
||||
|
||||
func IsNilish(val any) bool {
|
||||
if val == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(val)
|
||||
k := v.Kind()
|
||||
switch k {
|
||||
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer,
|
||||
reflect.UnsafePointer, reflect.Interface, reflect.Slice:
|
||||
return v.IsNil()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue