Skip to content

Commit

Permalink
ensure that template files are closed
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Rubin <jrubin@zvelo.com>
  • Loading branch information
Joshua Rubin committed Jun 4, 2015
1 parent da7d44b commit 28ca1d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/envetcd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const (
name = "envetcd"
version = "0.3.3"
version = "0.3.4"
)

type configT struct {
Expand Down
11 changes: 6 additions & 5 deletions envetcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,19 @@ func processTemplates(keyPairs KeyPairs, templateFiles []string) {
continue
}

outFileName := tmpl[0 : len(tmpl)-len(ext)]
outFile, err := os.Create(outFileName)
tpl, err := template.ParseFiles(tmpl)
if err != nil {
log.Printf("[WARN] error creating file (%s): %s", outFileName, err)
log.Printf("[WARN] error parsing template (%s): %s", tmpl, err)
continue
}

tpl, err := template.ParseFiles(tmpl)
outFileName := tmpl[0 : len(tmpl)-len(ext)]
outFile, err := os.Create(outFileName)
if err != nil {
log.Printf("[WARN] error parsing template (%s): %s", tmpl, err)
log.Printf("[WARN] error creating file (%s): %s", outFileName, err)
continue
}
defer outFile.Close()

log.Printf("[INFO] updating template %s", tmpl)
if err := tpl.Execute(outFile, keyPairs); err != nil {
Expand Down

0 comments on commit 28ca1d4

Please sign in to comment.