forked from hairyhenderson/gomplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.go
61 lines (55 loc) · 1.93 KB
/
funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gomplate
import (
"context"
"text/template"
"github.com/hairyhenderson/gomplate/v4/data"
"github.com/hairyhenderson/gomplate/v4/funcs" //nolint:staticcheck
"github.com/hairyhenderson/gomplate/v4/internal/config"
)
// Funcs -
//
// Deprecated: use [CreateFuncs] instead
func Funcs(d *data.Data) template.FuncMap {
return CreateFuncs(context.Background(), d)
}
// CreateFuncs - function mappings are created here
//
//nolint:staticcheck
func CreateFuncs(ctx context.Context, d *data.Data) template.FuncMap {
f := template.FuncMap{}
addToMap(f, funcs.CreateDataFuncs(ctx, d))
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))
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.
func SetExperimental(ctx context.Context) context.Context {
// This just calls the internal function. This is here to make experimental
// functions available to external packages.
return config.SetExperimental(ctx)
}