Open scruzin opened 1 week ago
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.
WithTemplates
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:
FmtSend
Send
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()) }
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 wrapsSend
method, would be implemented roughly as follows: