github.com/hairyhenderson/gomplate/v3@v3.11.7/funcs.go (about)

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