remove ginext/mongoext (no-dep lib)
This commit is contained in:
36
langext/pointer.go
Normal file
36
langext/pointer.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package langext
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func Ptr[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
func PtrInt32(v int32) *int32 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func PtrInt64(v int64) *int64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func PtrFloat32(v float32) *float32 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func PtrFloat64(v float64) *float64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func IsNil(i interface{}) bool {
|
||||
if i == nil {
|
||||
return true
|
||||
}
|
||||
switch reflect.TypeOf(i).Kind() {
|
||||
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
|
||||
return reflect.ValueOf(i).IsNil()
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user