pcmt/app/assets.go
leo d99d86a2be
All checks were successful
continuous-integration/drone/push Build is passing
go(app): use embedded variable value
2023-04-26 23:11:58 +02:00

56 lines
971 B
Go

package app
import (
"io/fs"
"net/http"
"os"
)
func (a *App) getAssets() http.FileSystem {
live := a.config.LiveMode
if live {
a.logger.Info("assets loaded in live mode")
return http.FS(os.DirFS("assets"))
}
a.logger.Info("assets loaded in embed mode")
fsys, err := fs.Sub(a.embeds.assets, "assets")
if err != nil {
panic(err)
}
return http.FS(fsys)
}
func (a *App) getTemplates() fs.FS {
live := a.config.LiveMode
if live {
a.logger.Info("templates loaded in live mode")
_, err := os.ReadDir("templates")
if err != nil {
a.Logger().Error("templates dir does not exist or is not accessible, check permissions")
panic(err)
}
return os.DirFS("templates")
}
a.logger.Info("templates loaded in embed mode")
fsys, err := fs.Sub(a.embeds.templates, "templates")
if err != nil {
panic(err)
}
// alt:
// func (a *App) getTemplates(live bool) http.FileSystem {
// return http.FS(os.DirFS("../templates"))
return fsys
}