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
1 changed files with 9 additions and 0 deletions
|
@ -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