Stephen McQuay
f9d2d247bc
I am trying to match what Jeff did in his https://github.com/zeebo/gostbook example.
26 lines
473 B
Go
26 lines
473 B
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
var cachedTemplates = map[string]*template.Template{}
|
|
var cachedMutex sync.Mutex
|
|
|
|
func T(name string) *template.Template {
|
|
cachedMutex.Lock()
|
|
defer cachedMutex.Unlock()
|
|
if t, ok := cachedTemplates[name]; ok {
|
|
return t
|
|
}
|
|
t := template.New("_base.html")
|
|
t = template.Must(t.ParseFiles(
|
|
"templates/_base.html",
|
|
filepath.Join(*template_dir, name),
|
|
))
|
|
cachedTemplates[name] = t
|
|
return t
|
|
}
|