Refactor buffer initialization to use bytes.NewBuffer

Replaced direct bytes.Buffer{} initialization with bytes.NewBuffer(nil) for better consistency and potential performance improvements. This refactor affects both the HTML and plain text alternative writers.
This commit is contained in:
Winni Neessen 2024-10-27 15:17:30 +01:00
parent 254dc81706
commit 84f9d0583d
Signed by: wneessen
GPG key ID: 385AC9889632126E

12
msg.go
View file

@ -1786,11 +1786,11 @@ func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opt
if tpl == nil { if tpl == nil {
return errors.New(errTplPointerNil) return errors.New(errTplPointerNil)
} }
buffer := bytes.Buffer{} buffer := bytes.NewBuffer(nil)
if err := tpl.Execute(&buffer, data); err != nil { if err := tpl.Execute(buffer, data); err != nil {
return fmt.Errorf(errTplExecuteFailed, err) return fmt.Errorf(errTplExecuteFailed, err)
} }
writeFunc := writeFuncFromBuffer(&buffer) writeFunc := writeFuncFromBuffer(buffer)
m.AddAlternativeWriter(TypeTextHTML, writeFunc, opts...) m.AddAlternativeWriter(TypeTextHTML, writeFunc, opts...)
return nil return nil
} }
@ -1816,11 +1816,11 @@ func (m *Msg) AddAlternativeTextTemplate(tpl *tt.Template, data interface{}, opt
if tpl == nil { if tpl == nil {
return errors.New(errTplPointerNil) return errors.New(errTplPointerNil)
} }
buffer := bytes.Buffer{} buffer := bytes.NewBuffer(nil)
if err := tpl.Execute(&buffer, data); err != nil { if err := tpl.Execute(buffer, data); err != nil {
return fmt.Errorf(errTplExecuteFailed, err) return fmt.Errorf(errTplExecuteFailed, err)
} }
writeFunc := writeFuncFromBuffer(&buffer) writeFunc := writeFuncFromBuffer(buffer)
m.AddAlternativeWriter(TypeTextPlain, writeFunc, opts...) m.AddAlternativeWriter(TypeTextPlain, writeFunc, opts...)
return nil return nil
} }