You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
754 B
Go
37 lines
754 B
Go
1 year ago
|
package preview
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"text/template"
|
||
|
|
||
|
"github.com/containrrr/watchtower/pkg/notifications/preview/data"
|
||
|
"github.com/containrrr/watchtower/pkg/notifications/templates"
|
||
|
)
|
||
|
|
||
|
func Render(input string, states []data.State, loglevels []data.LogLevel) (string, error) {
|
||
|
|
||
|
data := data.New()
|
||
|
|
||
|
tpl, err := template.New("").Funcs(templates.Funcs).Parse(input)
|
||
|
if err != nil {
|
||
|
return "", fmt.Errorf("failed to parse template: %e", err)
|
||
|
}
|
||
|
|
||
|
for _, state := range states {
|
||
|
data.AddFromState(state)
|
||
|
}
|
||
|
|
||
|
for _, level := range loglevels {
|
||
|
data.AddLogEntry(level)
|
||
|
}
|
||
|
|
||
|
var buf strings.Builder
|
||
|
err = tpl.Execute(&buf, data)
|
||
|
if err != nil {
|
||
|
return "", fmt.Errorf("failed to execute template: %e", err)
|
||
|
}
|
||
|
|
||
|
return buf.String(), nil
|
||
|
}
|