plugin/template: Add parseInt template function (#5609)

* plugin/template: Add parseInt template function

Signed-off-by: Erik Johansson <ejohansson@spotify.com>
This commit is contained in:
Erik Johansson
2022-09-15 12:25:58 -07:00
committed by GitHub
parent 7beb76c045
commit e93e932ce8
5 changed files with 116 additions and 20 deletions

View File

@@ -150,6 +150,13 @@ func executeRRTemplate(server, view, section string, template *gotmpl.Template,
return rr, nil
}
func newTemplate(name, text string) (*gotmpl.Template, error) {
funcMap := gotmpl.FuncMap{
"parseInt": strconv.ParseUint,
}
return gotmpl.New(name).Funcs(funcMap).Parse(text)
}
func (t template) match(ctx context.Context, state request.Request) (*templateData, bool, bool) {
q := state.Req.Question[0]
data := &templateData{md: metadata.ValueFuncs(ctx), Remote: state.IP()}