Simplify implementation of func

This commit is contained in:
Svilen Markov 2025-05-16 18:44:54 +01:00
parent 32db59fda2
commit bcef9fbd61

View File

@ -414,14 +414,6 @@ func customAPIDoMathOp[T int | float64](a, b T, op string) T {
return 0 return 0
} }
return a / b return a / b
case "mod":
ai, bi := any(a), any(b)
aint, aok := ai.(int)
bint, bok := bi.(int)
if aok && bok && bint != 0 {
return T(aint % bint)
}
return 0
} }
return 0 return 0
} }
@ -487,8 +479,11 @@ var customAPITemplateFuncs = func() template.FuncMap {
"div": func(a, b any) any { "div": func(a, b any) any {
return doMathOpWithAny(a, b, "div") return doMathOpWithAny(a, b, "div")
}, },
"mod": func(a, b int) any { "mod": func(a, b int) int {
return doMathOpWithAny(a, b, "mod") if b == 0 {
return 0
}
return a % b
}, },
"now": func() time.Time { "now": func() time.Time {
return time.Now() return time.Now()