summaryrefslogtreecommitdiff
path: root/funcs/env.go
diff options
context:
space:
mode:
Diffstat (limited to 'funcs/env.go')
-rw-r--r--funcs/env.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/funcs/env.go b/funcs/env.go
new file mode 100644
index 00000000..40c10ff9
--- /dev/null
+++ b/funcs/env.go
@@ -0,0 +1,34 @@
+package funcs
+
+import (
+ "sync"
+
+ "github.com/hairyhenderson/gomplate/env"
+)
+
+var (
+ ef *EnvFuncs
+ efInit sync.Once
+)
+
+// EnvNS - the Env namespace
+func EnvNS() *EnvFuncs {
+ efInit.Do(func() { ef = &EnvFuncs{} })
+ return ef
+}
+
+// AddEnvFuncs -
+func AddEnvFuncs(f map[string]interface{}) {
+ f["env"] = EnvNS
+
+ // global aliases - for backwards compatibility
+ f["getenv"] = EnvNS().Getenv
+}
+
+// EnvFuncs -
+type EnvFuncs struct{}
+
+// Getenv -
+func (f *EnvFuncs) Getenv(key string, def ...string) string {
+ return env.Getenv(key, def...)
+}