Skip to content

Commit

Permalink
Refactor writer
Browse files Browse the repository at this point in the history
In this commit we move the template out of the method for readability.
Also, because tmpl.Execute returns an error we don't actually need to do
error checking in the method. We can just pass the result (error or nil)
back to the caller.
  • Loading branch information
chelnak committed Jul 10, 2022
1 parent e753318 commit 5175311
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions internal/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
"github.com/chelnak/gh-changelog/internal/changelog"
)

func Write(writer io.Writer, changelog changelog.Changelog) error {
var tmplSrc = `# Changelog
var tmplSrc = `# Changelog
All notable changes to this project will be documented in this file.
Expand Down Expand Up @@ -77,11 +76,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
{{- end}}
{{- end}}`

func Write(writer io.Writer, changelog changelog.Changelog) error {
tmpl := template.Must(template.New("changelog").Parse(tmplSrc))

err := tmpl.Execute(writer, changelog)
if err != nil {
return err
}
return nil
return tmpl.Execute(writer, changelog)
}

0 comments on commit 5175311

Please sign in to comment.