forked from kevinburke/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
43 lines (40 loc) · 872 Bytes
/
template.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
package xbindata
import (
"bytes"
"context"
"errors"
"fmt"
"path"
"path/filepath"
"strings"
"text/template"
)
func (i *ManyConfigInput) format(ctx context.Context, key, value string, envs ...map[string]string) (v string, err error) {
defer func() {
if err != nil {
err = errors.New(fmt.Sprint("format{"+key+"}:", err.Error()))
}
}()
env := Env(append([]map[string]string{ContextEnv(ctx)}, envs...)...)
if strings.ContainsRune(value, '{') {
var t *template.Template
if t, err = template.New("").Parse(value); err != nil {
return
}
var buf bytes.Buffer
if err = t.Execute(&buf, map[string]interface{}{
"pclean": path.Clean,
"pjoin": path.Join,
"fpclean": filepath.Clean,
"fpjoin": filepath.Join,
"Env": env,
"PKG": i.Pkg,
}); err != nil {
return
}
v = buf.String()
} else {
v = value
}
return
}