aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-14 09:10:51 +0800
committerGitHub <noreply@github.com>2024-03-14 01:10:51 +0000
commit43de021ac1ca017212ec75fd88a8a80a9db27c4c (patch)
treeb83d85cef53695c64b54453d0b2bd37e69375f45 /modules
parent83ba882bab7e1545fe02cd41f554ae41b83a6040 (diff)
downloadgitea-43de021ac1ca017212ec75fd88a8a80a9db27c4c.tar.gz
gitea-43de021ac1ca017212ec75fd88a8a80a9db27c4c.zip
Add test for webhook (#29755)
Follow #29690
Diffstat (limited to 'modules')
-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
+}