Skip to content

Commit

Permalink
Refactor buffer initialization to use bytes.NewBuffer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wneessen committed Oct 27, 2024
1 parent 254dc81 commit 84f9d05
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1786,11 +1786,11 @@ func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opt
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.AddAlternativeWriter(TypeTextHTML, writeFunc, opts...)
return nil
}
Expand All @@ -1816,11 +1816,11 @@ func (m *Msg) AddAlternativeTextTemplate(tpl *tt.Template, data interface{}, opt
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.AddAlternativeWriter(TypeTextPlain, writeFunc, opts...)
return nil
}
Expand Down

0 comments on commit 84f9d05

Please sign in to comment.