From ebb97fb7367fb983cffc1935a8fb57e4b80f5249 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Thu, 25 Jan 2024 20:11:31 -0500 Subject: Move funcs package to internal (#1977) Signed-off-by: Dave Henderson --- internal/funcs/env.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 internal/funcs/env.go (limited to 'internal/funcs/env.go') diff --git a/internal/funcs/env.go b/internal/funcs/env.go new file mode 100644 index 00000000..0df63b3e --- /dev/null +++ b/internal/funcs/env.go @@ -0,0 +1,49 @@ +package funcs + +import ( + "context" + + "github.com/hairyhenderson/gomplate/v4/conv" + "github.com/hairyhenderson/gomplate/v4/env" +) + +// EnvNS - the Env namespace +// +// Deprecated: don't use +func EnvNS() *EnvFuncs { + return &EnvFuncs{} +} + +// AddEnvFuncs - +// +// Deprecated: use [CreateEnvFuncs] instead +func AddEnvFuncs(f map[string]interface{}) { + for k, v := range CreateEnvFuncs(context.Background()) { + f[k] = v + } +} + +// CreateEnvFuncs - +func CreateEnvFuncs(ctx context.Context) map[string]interface{} { + ns := &EnvFuncs{ctx} + + return map[string]interface{}{ + "env": func() interface{} { return ns }, + "getenv": ns.Getenv, + } +} + +// EnvFuncs - +type EnvFuncs struct { + ctx context.Context +} + +// Getenv - +func (EnvFuncs) Getenv(key interface{}, def ...string) string { + return env.Getenv(conv.ToString(key), def...) +} + +// ExpandEnv - +func (EnvFuncs) ExpandEnv(s interface{}) string { + return env.ExpandEnv(conv.ToString(s)) +} -- cgit v1.2.3