Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-29 05:06:11 +01:00

cherry pick only IfZero from (#29755)

original commit:
  Author: wxiaoguang <wxiaoguang@gmail.com>
  Date:   Thu Mar 14 09:10:51 2024 +0800

  Add test for webhook (#29755)

  Follow #29690
This commit is contained in:
Shiny Nematoda 2024-03-25 15:35:14 +00:00
parent 1e7a6483b8
commit 82851f429a

View file

@ -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
}