Template execution rework

This commit is contained in:
binwiederhier
2026-07-08 21:08:07 +02:00
parent 7b54850c16
commit a001ac5195
20 changed files with 2795 additions and 48 deletions
+3 -3
View File
@@ -5,7 +5,6 @@ import (
"path/filepath"
"reflect"
"strings"
"text/template"
"time"
)
@@ -21,8 +20,9 @@ const (
//
// tpl := template.New("foo").Funcs(sprig.FuncMap()))
//
// TxtFuncMap returns a 'text/template'.FuncMap
func TxtFuncMap() template.FuncMap {
// TxtFuncMap returns the function map as a plain map[string]any, assignable to any text/template or
// html/template FuncMap (including ntfy's vendored internal/template).
func TxtFuncMap() map[string]any {
return map[string]any{
// Date functions
"ago": dateAgo,
-34
View File
@@ -1,34 +0,0 @@
package util
import (
"errors"
"io"
"time"
)
// ErrWriteTimeout is returned when a write timed out
var ErrWriteTimeout = errors.New("write operation failed due to timeout")
// TimeoutWriter wraps an io.Writer that will time out after the given timeout
type TimeoutWriter struct {
writer io.Writer
timeout time.Duration
start time.Time
}
// NewTimeoutWriter creates a new TimeoutWriter
func NewTimeoutWriter(w io.Writer, timeout time.Duration) *TimeoutWriter {
return &TimeoutWriter{
writer: w,
timeout: timeout,
start: time.Now(),
}
}
// Write implements the io.Writer interface, failing if called after the timeout period from creation.
func (tw *TimeoutWriter) Write(p []byte) (n int, err error) {
if time.Since(tw.start) > tw.timeout {
return 0, ErrWriteTimeout
}
return tw.writer.Write(p)
}