summaryrefslogtreecommitdiff
path: root/internal/funcs/env.go
blob: 5ec5a17a07c898d7eac4f8ee211c0a4ae85979c9 (plain)
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
package funcs

import (
	"context"

	"github.com/hairyhenderson/gomplate/v4/conv"
	"github.com/hairyhenderson/gomplate/v4/env"
)

// CreateEnvFuncs -
func CreateEnvFuncs(ctx context.Context) map[string]any {
	ns := &EnvFuncs{ctx}

	return map[string]any{
		"env":    func() any { return ns },
		"getenv": ns.Getenv,
	}
}

// EnvFuncs -
type EnvFuncs struct {
	ctx context.Context
}

// Getenv -
func (EnvFuncs) Getenv(key any, def ...string) string {
	return env.Getenv(conv.ToString(key), def...)
}

// ExpandEnv -
func (EnvFuncs) ExpandEnv(s any) string {
	return env.ExpandEnv(conv.ToString(s))
}