From bf9ec094bfdb1cd3444834c00508918f758efed3 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 15 Jul 2022 19:25:05 +0200 Subject: [PATCH] Add "mod" function for modulo in templating Signed-off-by: Knut Ahlers --- internal/template/numeric/numeric.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/template/numeric/numeric.go b/internal/template/numeric/numeric.go index b4eadaa..28d33d3 100644 --- a/internal/template/numeric/numeric.go +++ b/internal/template/numeric/numeric.go @@ -9,6 +9,7 @@ import ( func Register(args plugins.RegistrationArguments) error { args.RegisterTemplateFunction("add", plugins.GenericTemplateFunctionGetter(add)) args.RegisterTemplateFunction("div", plugins.GenericTemplateFunctionGetter(div)) + args.RegisterTemplateFunction("mod", plugins.GenericTemplateFunctionGetter(mod)) args.RegisterTemplateFunction("mul", plugins.GenericTemplateFunctionGetter(mul)) args.RegisterTemplateFunction("multiply", plugins.GenericTemplateFunctionGetter(mul)) // DEPRECATED args.RegisterTemplateFunction("pow", plugins.GenericTemplateFunctionGetter(math.Pow)) @@ -18,5 +19,6 @@ func Register(args plugins.RegistrationArguments) error { func add(m1, m2 float64) float64 { return m1 + m2 } func div(m1, m2 float64) float64 { return m1 / m2 } +func mod(m1, m2 int64) int64 { return m1 % m2 } func mul(m1, m2 float64) float64 { return m1 * m2 } func sub(m1, m2 float64) float64 { return m1 - m2 }