github.com/gogf/gf/v2@v2.7.4/internal/utils/utils_reflect.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package utils 8 9 import ( 10 "reflect" 11 ) 12 13 // CanCallIsNil Can reflect.Value call reflect.Value.IsNil. 14 // It can avoid reflect.Value.IsNil panics. 15 func CanCallIsNil(v interface{}) bool { 16 rv, ok := v.(reflect.Value) 17 if !ok { 18 return false 19 } 20 switch rv.Kind() { 21 case reflect.Interface, reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer: 22 return true 23 default: 24 return false 25 } 26 }