forked from Cliffbreak/tsviewer
36 lines
588 B
Go
36 lines
588 B
Go
|
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
|
||
|
}
|