From 7ebab7875bde8c99c091e85808bc9ee5a89fa317 Mon Sep 17 00:00:00 2001 From: Zachary Schulze Date: Fri, 23 Jul 2021 11:39:30 -0700 Subject: [PATCH] update - Added AddHelperFunction comment/usage - AddHelperFunction returns err on duplicate key definitions --- v2/pkg/operators/common/dsl/dsl.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/v2/pkg/operators/common/dsl/dsl.go b/v2/pkg/operators/common/dsl/dsl.go index ea8a97b93..37820b9a9 100644 --- a/v2/pkg/operators/common/dsl/dsl.go +++ b/v2/pkg/operators/common/dsl/dsl.go @@ -7,6 +7,7 @@ import ( "crypto/sha256" "encoding/base64" "encoding/hex" + "errors" "fmt" "html" "math" @@ -234,15 +235,18 @@ var functions = map[string]govaluate.ExpressionFunction{ }, } -// HelperFunctions contains the dsl helper functions +// HelperFunctions returns the dsl helper functions func HelperFunctions() map[string]govaluate.ExpressionFunction { return functions } -func AddHelperFunction(key string, value func(args ...interface{}) (interface{}, error)) { +// AddHelperFunction allows creation of additiona helper functions to be supported with templates +func AddHelperFunction(key string, value func(args ...interface{}) (interface{}, error)) error { if _, ok := functions[key]; !ok { functions[key] = value + return nil } + return errors.New("duplicate helper function key defined") } func reverseString(s string) string {