feat: add IsNilOrZero utility function to common package

This commit is contained in:
2025-10-12 21:11:51 +04:00
parent d1ea7874fe
commit 82197ac9b9
2 changed files with 24 additions and 0 deletions

View File

@@ -22,6 +22,20 @@ num := 42
ptr := common.ToPtr(num) // *int 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 ### parser
String parsing utilities with generic type support. String parsing utilities with generic type support.

10
common/compare.go Normal file
View 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
}