Skip to content

Commit

Permalink
nsqadmin: only parse templates once
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Mar 28, 2015
1 parent 5606c5c commit 8908e1d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nsqadmin/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package templates
import (
"html/template"
"log"
"sync"
)

var sources map[string]string
var parser sync.Once
var T *template.Template

func init() {
Expand All @@ -24,10 +26,12 @@ func registerTemplate(name string, source string) {
}

func Parse() {
for name, source := range sources {
_, err := T.New(name).Parse(source)
if err != nil {
log.Fatalf("ERROR: failed to parse template %s - %s", name, err)
parser.Do(func() {
for name, source := range sources {
_, err := T.New(name).Parse(source)
if err != nil {
log.Fatalf("ERROR: failed to parse template %s - %s", name, err)
}
}
}
})
}

0 comments on commit 8908e1d

Please sign in to comment.