feat: add tplprev wasm

This commit is contained in:
nils måsén 2023-10-02 11:37:30 +02:00
parent 9b28fbc24d
commit 16883d21c0
11 changed files with 1348 additions and 19 deletions

View file

@ -59,13 +59,3 @@ func marshalReports(reports []t.ContainerReport) []jsonMap {
}
var _ json.Marshaler = &Data{}
func toJSON(v interface{}) string {
var bytes []byte
var err error
if bytes, err = json.MarshalIndent(v, "", " "); err != nil {
LocalLog.Errorf("failed to marshal JSON in notification template: %v", err)
return ""
}
return string(bytes)
}

View file

@ -10,10 +10,9 @@ import (
"github.com/containrrr/shoutrrr"
"github.com/containrrr/shoutrrr/pkg/types"
"github.com/containrrr/watchtower/pkg/notifications/templates"
t "github.com/containrrr/watchtower/pkg/types"
log "github.com/sirupsen/logrus"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// LocalLog is a logrus logger that does not send entries as notifications
@ -208,13 +207,8 @@ func (n *shoutrrrTypeNotifier) Fire(entry *log.Entry) error {
}
func getShoutrrrTemplate(tplString string, legacy bool) (tpl *template.Template, err error) {
funcs := template.FuncMap{
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
"ToJSON": toJSON,
"Title": cases.Title(language.AmericanEnglish).String,
}
tplBase := template.New("").Funcs(funcs)
tplBase := template.New("").Funcs(templates.Funcs)
if builtin, found := commonTemplates[tplString]; found {
log.WithField(`template`, tplString).Debug(`Using common template`)
@ -242,3 +236,7 @@ func getShoutrrrTemplate(tplString string, legacy bool) (tpl *template.Template,
return
}
func GetShoutrrrTemplate(tplString string) (tpl *template.Template, err error) {
return getShoutrrrTemplate(tplString, false)
}

View file

@ -0,0 +1,27 @@
package templates
import (
"encoding/json"
"fmt"
"strings"
"text/template"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
var Funcs = template.FuncMap{
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
"ToJSON": toJSON,
"Title": cases.Title(language.AmericanEnglish).String,
}
func toJSON(v interface{}) string {
var bytes []byte
var err error
if bytes, err = json.MarshalIndent(v, "", " "); err != nil {
return fmt.Sprintf("failed to marshal JSON in notification template: %v", err)
}
return string(bytes)
}