You've already forked watchtower
							
							
				mirror of
				https://github.com/containrrr/watchtower.git
				synced 2025-10-31 00:17:44 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			754 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			754 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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
 | |
| }
 |