Skip to content
Permalink
86d059bf99
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
24 lines (21 sloc) 522 Bytes
package templates
import (
"embed"
"io/fs"
"os"
"path/filepath"
)
//go:embed static
var templateFS embed.FS
// Read reads either template from disk if it exists, or from embedded template
func Read(path string) ([]byte, error) {
if _, err := os.Stat(filepath.Clean(path)); err == nil {
return os.ReadFile(filepath.Clean(path))
}
// remove "static/" prefix from path
var contentFS, err = fs.Sub(templateFS, "static")
if err != nil {
return nil, err
}
return fs.ReadFile(contentFS, filepath.Clean(path))
}