notify: Emails formatted by templates
- Dominant language
- Go
- Stars
- 1
- Forks
- 3
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 6
Description
At present, email bodies are simple strings constructed by the sender, which limits their composition.
It is proposed to have a `WithTemplates` option, whereby templates are optionally supplied to the Notifier.
The notifier would include an optional property:
`templates *template.Template`
Templates would be keyed by the notification **kind**.
A new `FmtSend`, that wraps `Send` method, would be implemented roughly as follows:
```
func (n *Notifier) FmtSend(ctx context.Context, skey int64, kind string, data interface{}) error {
if n.templates == nil {
return errors.New("missing templates")
}
var b bytes.Buffer
// Look up the template for this kind of notification.
err = n.templates.ExecuteTemplate(&b, kind, data) {
if err != nil {
// Handle error
return err
}
return n.Send(ctx, skey, kind, b.String())
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.