Add ability to specify error template functions
diff --git a/errors.go b/errors.go index a541a73..2ccf0cc 100644 --- a/errors.go +++ b/errors.go
@@ -257,6 +257,10 @@ errorTemplates.Lock() tpl = errorTemplates.New(s) + if ErrorTemplateFuncs != nil { + tpl.Funcs(ErrorTemplateFuncs) + } + tpl, err = tpl.Parse(s) errorTemplates.Unlock()
diff --git a/schema.go b/schema.go index cf3cbc7..eeb5f31 100644 --- a/schema.go +++ b/schema.go
@@ -31,6 +31,7 @@ "errors" "reflect" "regexp" + "text/template" "github.com/xeipuuv/gojsonreference" ) @@ -39,6 +40,9 @@ // Locale is the default locale to use // Library users can overwrite with their own implementation Locale locale = DefaultLocale{} + + // ErrorTemplateFuncs allows you to define custom template funcs for use in localization. + ErrorTemplateFuncs template.FuncMap ) func NewSchema(l JSONLoader) (*Schema, error) {