Documentation ¶
Index ¶
- func AssertNotNilAndIsPointer(ptr interface{}) error
- func ExtractPointer(value any) any
- func IsPointer(obj interface{}) bool
- func IsPointer1(obj interface{}) bool
- func IsPointer2(obj interface{}) bool
- func Of[T any](v T) *T
- func ToString(ptr interface{}) string
- func UnwarpOr[T any](p *T, fallback T) T
- func UnwarpOrDefault[T any](p *T) T
- func Unwrap[T any](p *T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertNotNilAndIsPointer ¶
func AssertNotNilAndIsPointer(ptr interface{}) error
AssertNotNilAndIsPointer
合法的传参: (1) ptr != nil(值非nil) (2) ptr的类型为"指针"
func ExtractPointer ¶ added in v2.8.152
ExtractPointer 返回传入interface的底层值.
func IsPointer ¶
func IsPointer(obj interface{}) bool
IsPointer 传参的类型是否为指针?
PS: 传参的值无影响,即使其为nil.
@param obj 可以为nil
e.g.
type bean struct { } var b *bean = nil fmt.Println(ptrKit.IsPointer(b)) // true(类型为指针,虽然值为nil) fmt.Println(ptrKit.IsPointer(interface{}(nil))) // false
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 ToString ¶
func ToString(ptr interface{}) string
ToString 指针 => 指针的地址字符串(十六进制表示,前缀 0x)
e.g.
tmp := 1 (&tmp) => "0xc00000a228"
e.g.1
(nil) => "%!p(<nil>)"
func UnwarpOr ¶ added in v2.8.152
func UnwarpOr[T any](p *T, fallback T) T
UnwarpOr 返回指针的值,如果指针为零值,则返回fallback.
func UnwarpOrDefault ¶ added in v2.8.152
func UnwarpOrDefault[T any](p *T) T
UnwarpOrDefault 返回指针的值,如果指针为零值,则返回相应零值.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.