diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2025-03-09 20:14:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-10 00:14:46 +0000 |
| commit | bfa6b9dcef7592e6dd8225aaa0d0ab5aef5b3f84 (patch) | |
| tree | 7e844defee92dc3af320df20baa6f9b421d4a4c9 /funcs.go | |
| parent | 7942441e61471f578a57910b3aa93636f5a0310d (diff) | |
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 <dhenderson@gmail.com>
Diffstat (limited to 'funcs.go')
| -rw-r--r-- | funcs.go | 50 |
1 files changed, 22 insertions, 28 deletions
@@ -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. |
