From 432e21f162e1efd44523b8de07aa2b5cb81c3e2c Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 27 Oct 2024 14:33:00 +0100 Subject: [PATCH] Refactor buffer initialization in message template execution Change buffer initialization from an empty `bytes.Buffer` to `bytes.NewBuffer(nil)` to streamline buffer allocation. This adjustment ensures better flexibility and aligns with best practices in handling buffer slices. --- msg.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/msg.go b/msg.go index c770973..1fd97a4 100644 --- a/msg.go +++ b/msg.go @@ -1681,11 +1681,11 @@ func (m *Msg) SetBodyHTMLTemplate(tpl *ht.Template, data interface{}, opts ...Pa if tpl == nil { return errors.New(errTplPointerNil) } - buffer := bytes.Buffer{} - if err := tpl.Execute(&buffer, data); err != nil { + buffer := bytes.NewBuffer(nil) + if err := tpl.Execute(buffer, data); err != nil { return fmt.Errorf(errTplExecuteFailed, err) } - writeFunc := writeFuncFromBuffer(&buffer) + writeFunc := writeFuncFromBuffer(buffer) m.SetBodyWriter(TypeTextHTML, writeFunc, opts...) return nil }