go-tsviewer/gui/template.go

36 lines
588 B
Go
Raw Normal View History

2019-01-17 21:09:41 +00:00
package gui
import (
"fmt"
"html/template"
"io/ioutil"
"strings"
)
func LoadTemplates() (*template.Template, error) {
return loadTemplates("templates/")
}
func loadTemplates(path string) (*template.Template, error) {
dir, err := ioutil.ReadDir(path)
if err != nil {
return nil, err
}
var ff []string
for _, file := range dir {
filename := file.Name()
if strings.HasSuffix(filename, ".html") {
ff = append(ff, fmt.Sprintf("%s%s", path, filename))
}
}
templates, err := template.ParseFiles(ff...)
if err != nil {
return nil, err
}
return templates, nil
}