From bfa6b9dcef7592e6dd8225aaa0d0ab5aef5b3f84 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 9 Mar 2025 20:14:46 -0400 Subject: chore(refactoring): Refactor/modernizations (#2345) chore(refactoring): Refactor with modernization refactorings * range over int * replace interface{} with any * replace common map operations with maps.Copy/maps.Clone * simplifying loops with slices.Contains/ContainsFunc * modernize benchmarks with b.Loop * modernize tests with t.Context * use fmt.Appendf * range over strings.SplitSeq * use new stdlib crypto/pbkdf2 package --------- Signed-off-by: Dave Henderson --- funcs.go | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'funcs.go') diff --git a/funcs.go b/funcs.go index 93025f59..ea460432 100644 --- a/funcs.go +++ b/funcs.go @@ -2,6 +2,7 @@ package gomplate import ( "context" + "maps" "text/template" "github.com/hairyhenderson/gomplate/v4/internal/config" @@ -11,37 +12,30 @@ import ( // CreateFuncs - function mappings are created here func CreateFuncs(ctx context.Context) template.FuncMap { f := template.FuncMap{} - addToMap(f, funcs.CreateDataFuncs(ctx)) - addToMap(f, funcs.CreateAWSFuncs(ctx)) - addToMap(f, funcs.CreateGCPFuncs(ctx)) - addToMap(f, funcs.CreateBase64Funcs(ctx)) - addToMap(f, funcs.CreateNetFuncs(ctx)) - addToMap(f, funcs.CreateReFuncs(ctx)) - addToMap(f, funcs.CreateStringFuncs(ctx)) - addToMap(f, funcs.CreateEnvFuncs(ctx)) - addToMap(f, funcs.CreateConvFuncs(ctx)) - addToMap(f, funcs.CreateTimeFuncs(ctx)) - addToMap(f, funcs.CreateMathFuncs(ctx)) - addToMap(f, funcs.CreateCryptoFuncs(ctx)) - addToMap(f, funcs.CreateFileFuncs(ctx)) - addToMap(f, funcs.CreateFilePathFuncs(ctx)) - addToMap(f, funcs.CreatePathFuncs(ctx)) - addToMap(f, funcs.CreateSockaddrFuncs(ctx)) - addToMap(f, funcs.CreateTestFuncs(ctx)) - addToMap(f, funcs.CreateCollFuncs(ctx)) - addToMap(f, funcs.CreateUUIDFuncs(ctx)) - addToMap(f, funcs.CreateRandomFuncs(ctx)) - addToMap(f, funcs.CreateSemverFuncs(ctx)) + maps.Copy(f, funcs.CreateDataFuncs(ctx)) + maps.Copy(f, funcs.CreateAWSFuncs(ctx)) + maps.Copy(f, funcs.CreateGCPFuncs(ctx)) + maps.Copy(f, funcs.CreateBase64Funcs(ctx)) + maps.Copy(f, funcs.CreateNetFuncs(ctx)) + maps.Copy(f, funcs.CreateReFuncs(ctx)) + maps.Copy(f, funcs.CreateStringFuncs(ctx)) + maps.Copy(f, funcs.CreateEnvFuncs(ctx)) + maps.Copy(f, funcs.CreateConvFuncs(ctx)) + maps.Copy(f, funcs.CreateTimeFuncs(ctx)) + maps.Copy(f, funcs.CreateMathFuncs(ctx)) + maps.Copy(f, funcs.CreateCryptoFuncs(ctx)) + maps.Copy(f, funcs.CreateFileFuncs(ctx)) + maps.Copy(f, funcs.CreateFilePathFuncs(ctx)) + maps.Copy(f, funcs.CreatePathFuncs(ctx)) + maps.Copy(f, funcs.CreateSockaddrFuncs(ctx)) + maps.Copy(f, funcs.CreateTestFuncs(ctx)) + maps.Copy(f, funcs.CreateCollFuncs(ctx)) + maps.Copy(f, funcs.CreateUUIDFuncs(ctx)) + maps.Copy(f, funcs.CreateRandomFuncs(ctx)) + maps.Copy(f, funcs.CreateSemverFuncs(ctx)) return f } -// addToMap - add src's entries to dst -func addToMap(dst, src map[string]interface{}) { - for k, v := range src { - dst[k] = v - } -} - // SetExperimental enables experimental functions and features in the given // context. This must be done before creating functions. The set of experimental // features enabled by this is not fixed and will change over time. -- cgit v1.2.3