saasitone/templates/templates.go

30 lines
742 B
Go
Raw Normal View History

package templates
import (
"embed"
"io/fs"
"os"
"path"
"path/filepath"
"runtime"
)
//go:embed *
var templates embed.FS
// Get returns a file system containing all templates via embed.FS
func Get() embed.FS {
return templates
}
// GetOS returns a file system containing all templates which will load the files directly from the operating system.
// This should only be used for local development in order to facilitate live reloading.
func GetOS() fs.FS {
// Gets the complete templates directory path
// This is needed in case this is called from a package outside of main, such as within tests
_, b, _, _ := runtime.Caller(0)
d := path.Join(path.Dir(b))
p := filepath.Join(filepath.Dir(d), "templates")
return os.DirFS(p)
}