github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/funcs.go (about) 1 package gomplate 2 3 import ( 4 "context" 5 "text/template" 6 7 "github.com/hairyhenderson/gomplate/v4/data" 8 "github.com/hairyhenderson/gomplate/v4/internal/config" 9 "github.com/hairyhenderson/gomplate/v4/internal/funcs" 10 ) 11 12 // CreateFuncs - function mappings are created here 13 // 14 //nolint:staticcheck 15 func CreateFuncs(ctx context.Context, d *data.Data) template.FuncMap { 16 f := template.FuncMap{} 17 addToMap(f, funcs.CreateDataFuncs(ctx, d)) 18 addToMap(f, funcs.CreateAWSFuncs(ctx)) 19 addToMap(f, funcs.CreateGCPFuncs(ctx)) 20 addToMap(f, funcs.CreateBase64Funcs(ctx)) 21 addToMap(f, funcs.CreateNetFuncs(ctx)) 22 addToMap(f, funcs.CreateReFuncs(ctx)) 23 addToMap(f, funcs.CreateStringFuncs(ctx)) 24 addToMap(f, funcs.CreateEnvFuncs(ctx)) 25 addToMap(f, funcs.CreateConvFuncs(ctx)) 26 addToMap(f, funcs.CreateTimeFuncs(ctx)) 27 addToMap(f, funcs.CreateMathFuncs(ctx)) 28 addToMap(f, funcs.CreateCryptoFuncs(ctx)) 29 addToMap(f, funcs.CreateFileFuncs(ctx)) 30 addToMap(f, funcs.CreateFilePathFuncs(ctx)) 31 addToMap(f, funcs.CreatePathFuncs(ctx)) 32 addToMap(f, funcs.CreateSockaddrFuncs(ctx)) 33 addToMap(f, funcs.CreateTestFuncs(ctx)) 34 addToMap(f, funcs.CreateCollFuncs(ctx)) 35 addToMap(f, funcs.CreateUUIDFuncs(ctx)) 36 addToMap(f, funcs.CreateRandomFuncs(ctx)) 37 addToMap(f, funcs.CreateSemverFuncs(ctx)) 38 return f 39 } 40 41 // addToMap - add src's entries to dst 42 func addToMap(dst, src map[string]interface{}) { 43 for k, v := range src { 44 dst[k] = v 45 } 46 } 47 48 // SetExperimental enables experimental functions and features in the given 49 // context. This must be done before creating functions. The set of experimental 50 // features enabled by this is not fixed and will change over time. 51 func SetExperimental(ctx context.Context) context.Context { 52 // This just calls the internal function. This is here to make experimental 53 // functions available to external packages. 54 return config.SetExperimental(ctx) 55 }