aboutsummaryrefslogtreecommitdiffstats
path: root/modules/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/util/util.go')
-rw-r--r--modules/util/util.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/util/util.go b/modules/util/util.go
index 5c75158196..c94fb91047 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -212,3 +212,12 @@ func ToFloat64(number any) (float64, error) {
func ToPointer[T any](val T) *T {
return &val
}
+
+// IfZero returns "def" if "v" is a zero value, otherwise "v"
+func IfZero[T comparable](v, def T) T {
+ var zero T
+ if v == zero {
+ return def
+ }
+ return v
+}