error-pages/templates/embed.go
2024-06-22 03:32:10 +04:00

39 lines
709 B
Go

package templates
import (
"embed"
"io/fs"
"path/filepath"
"strings"
)
//go:embed *.html
var content embed.FS
func BuiltIn() map[string]string { // error check is covered by unit tests
var (
list, _ = fs.ReadDir(content, ".")
result = make(map[string]string, len(list))
)
for _, file := range list {
if data, err := fs.ReadFile(content, file.Name()); err == nil {
var (
fileName = filepath.Base(file.Name())
ext = filepath.Ext(fileName)
templateName string
)
if ext != "" && fileName != ext {
templateName = strings.TrimSuffix(fileName, ext)
} else {
templateName = fileName
}
result[templateName] = string(data)
}
}
return result
}