This repository has been archived on 2019-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
scoreboard/gui/template.go

35 lines
588 B
Go
Executable file

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
}