File: eval.go

package info (click to toggle)
golang-github-drone-envsubst 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 156 kB
  • sloc: makefile: 3
file content (19 lines) | stat: -rw-r--r-- 500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package envsubst

import "os"

// Eval replaces ${var} in the string based on the mapping function.
func Eval(s string, mapping func(string) string) (string, error) {
	t, err := Parse(s)
	if err != nil {
		return s, err
	}
	return t.Execute(mapping)
}

// EvalEnv replaces ${var} in the string according to the values of the
// current environment variables. References to undefined variables are
// replaced by the empty string.
func EvalEnv(s string) (string, error) {
	return Eval(s, os.Getenv)
}