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:
parent
1e7a6483b8
commit
82851f429a
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue