Skip to content

Commit

Permalink
Close #23: add function "now" to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tierpod committed Feb 3, 2022
1 parent 6b206a5 commit 14dbe3e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/dmarc-report-converter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"html/template"
"io/ioutil"
"time"

"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -96,11 +97,17 @@ func loadConfig(path string) (*config, error) {
default:
return nil, fmt.Errorf("unable to found template for format '%v' in templates folder", c.Output.Format)
}
c.Output.template = template.Must(template.New("report").Parse(t))
tmplFuncs := template.FuncMap{
"now": func(fmt string) string {
return time.Now().Format(fmt)
},
}

c.Output.template = template.Must(template.New("report").Funcs(tmplFuncs).Parse(t))

if !c.Output.isStdout() {
// load and parse output filename template
ft := template.Must(template.New("filename").Parse(c.Output.File))
ft := template.Must(template.New("filename").Funcs(tmplFuncs).Parse(c.Output.File))
c.Output.fileTemplate = ft
}

Expand Down

0 comments on commit 14dbe3e

Please sign in to comment.