mirror of
https://github.com/aykhans/go-utils.git
synced 2025-10-15 10:25:56 +00:00
feat: add IsNilOrZero utility function to common package
This commit is contained in:
14
README.md
14
README.md
@@ -22,6 +22,20 @@ num := 42
|
||||
ptr := common.ToPtr(num) // *int
|
||||
```
|
||||
|
||||
**IsNilOrZero** - Check if a pointer is nil or points to a zero value
|
||||
```go
|
||||
import "github.com/aykhans/go-utils/common"
|
||||
|
||||
var ptr *int
|
||||
common.IsNilOrZero(ptr) // true (nil pointer)
|
||||
|
||||
num := 0
|
||||
common.IsNilOrZero(&num) // true (zero value)
|
||||
|
||||
num = 42
|
||||
common.IsNilOrZero(&num) // false (non-zero value)
|
||||
```
|
||||
|
||||
### parser
|
||||
|
||||
String parsing utilities with generic type support.
|
||||
|
10
common/compare.go
Normal file
10
common/compare.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package common
|
||||
|
||||
func IsNilOrZero[T comparable](value *T) bool {
|
||||
if value == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
var zero T
|
||||
return *value == zero
|
||||
}
|
Reference in New Issue
Block a user