2023-04-02 11:11:09 +02:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
2023-04-06 13:08:30 +02:00
|
|
|
// DefaultRenderTemplate is an adapter to implement the builtin golang text template renderer as resource.RenderTemplate.
|
2023-04-02 11:11:09 +02:00
|
|
|
func DefaultRenderTemplate(r Resource, sym string, values map[string]string) (string, error) {
|
|
|
|
v, err := r.GetTemplate(sym)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
tp, err := template.New("tester").Option("missingkey=error").Parse(v)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
b := bytes.NewBuffer([]byte{})
|
|
|
|
err = tp.Execute(b, values)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return b.String(), err
|
|
|
|
}
|
2023-04-03 00:53:21 +02:00
|
|
|
|