Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromPtr ¶
func FromPtr[T any](x *T) T
FromPtr 返回指针的值(如果指针为nil则返回T类型的零值).
@param x 可以为nil(此时将返回类型T的zero value) @return 可能为nil
e.g.
str := "测试test" value := ptrKit.FromPtr(&str) fmt.Println(value) // "测试test" value = ptrKit.FromPtr[string](nil) fmt.Println(value) // ""
func FromPtrOr ¶
func FromPtrOr[T any](x *T, fallback T) T
FromPtrOr 返回指针的值(如果指针为nil则返回传参fallback).
@param x 可以为nil(此时将返回传参fallback)
func IsPointer1 ¶
func IsPointer1(obj interface{}) bool
IsPointer1 *
- 判断参数obj是否为指针(pointer).
- 参考:github.com/json-iterator/go => reflect.go => func (iter *Iterator) ReadVal(obj interface{}) *
- @param obj nil => false
func ToPtr ¶
func ToPtr[T any](x T) *T
ToPtr Returns a pointer copy of value.
@param x 可以为nil(但需要指定类型T,且这么干貌似没意义)
e.g.
ptr := ptrKit.ToPtr("hello world") fmt.Println(ptr) // 0x140000105e0
e.g.1 x == nil的情况
ptr := ptrKit.ToPtr[interface{}](nil) fmt.Println(ptr) // 0x1400010c5c0 fmt.Println(ptr == nil) // false fmt.Println(interfaceKit.IsNil(ptr)) // false
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.