1
0
Fork 0
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:
Mikhail Iudin 2025-02-25 13:50:20 +01:00
parent b04a48144d
commit fbf22655fe
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
3 changed files with 33 additions and 1 deletions

View 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
}