From bcef9fbd6183d61fcc1757f745d88cd4308ba712 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Fri, 16 May 2025 18:44:54 +0100 Subject: [PATCH] Simplify implementation of func --- internal/glance/widget-custom-api.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go index d95d885..1d8bf2f 100644 --- a/internal/glance/widget-custom-api.go +++ b/internal/glance/widget-custom-api.go @@ -414,14 +414,6 @@ func customAPIDoMathOp[T int | float64](a, b T, op string) T { return 0 } 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 } @@ -487,8 +479,11 @@ var customAPITemplateFuncs = func() template.FuncMap { "div": func(a, b any) any { return doMathOpWithAny(a, b, "div") }, - "mod": func(a, b int) any { - return doMathOpWithAny(a, b, "mod") + "mod": func(a, b int) int { + if b == 0 { + return 0 + } + return a % b }, "now": func() time.Time { return time.Now()