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.
This commit is contained in:
Winni Neessen 2024-10-27 14:33:00 +01:00
parent 0aa81d724b
commit 432e21f162
Signed by: wneessen
GPG key ID: 385AC9889632126E

6
msg.go
View file

@ -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
}