2023-07-21 08:59:02 +00:00
|
|
|
package template
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-25 14:42:53 +00:00
|
|
|
"regexp"
|
2023-07-21 08:59:02 +00:00
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ErrFail struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err ErrFail) Error() string {
|
|
|
|
return err.msg
|
|
|
|
}
|
|
|
|
|
|
|
|
var helperFuncs = template.FuncMap{
|
|
|
|
"fail": func(format string, args ...any) (any, error) {
|
|
|
|
return nil, ErrFail{fmt.Sprintf(format, args...)}
|
|
|
|
},
|
2023-07-25 14:42:53 +00:00
|
|
|
// Alias for https://pkg.go.dev/regexp#Compile. Allows usage of all methods of regexp.Regexp
|
|
|
|
"regexp": func(expr string) (*regexp.Regexp, error) {
|
|
|
|
return regexp.Compile(expr)
|
|
|
|
},
|
2023-07-21 08:59:02 +00:00
|
|
|
}
|