Refactor buffer creation in msg.go

Replace `bytes.Buffer{}` with `bytes.NewBuffer(nil)` for buffer instantiation to improve clarity and consistency. This change simplifies the buffer creation process and aligns it with common Go practices.
This commit is contained in:
Winni Neessen 2024-10-27 14:55:51 +01:00
parent 35ffc95102
commit f8caa5599b
Signed by: wneessen
GPG key ID: 385AC9889632126E

6
msg.go
View file

@ -1712,11 +1712,11 @@ func (m *Msg) SetBodyTextTemplate(tpl *tt.Template, data interface{}, opts ...Pa
if tpl == nil { if tpl == nil {
return errors.New(errTplPointerNil) return errors.New(errTplPointerNil)
} }
buf := bytes.Buffer{} buffer := bytes.NewBuffer(nil)
if err := tpl.Execute(&buf, data); err != nil { if err := tpl.Execute(buffer, data); err != nil {
return fmt.Errorf(errTplExecuteFailed, err) return fmt.Errorf(errTplExecuteFailed, err)
} }
writeFunc := writeFuncFromBuffer(&buf) writeFunc := writeFuncFromBuffer(buffer)
m.SetBodyWriter(TypeTextPlain, writeFunc, opts...) m.SetBodyWriter(TypeTextPlain, writeFunc, opts...)
return nil return nil
} }