pcmt/app/assets.go
leo 8622539294
All checks were successful
continuous-integration/drone/push Build is passing
chore: clean up app pkg
2023-04-19 21:46:56 +02:00

52 lines
933 B
Go

package app
import (
"io/fs"
"net/http"
"os"
)
func (a *App) getAssets(live bool) http.FileSystem {
if live {
a.logger.Info("assets loaded in live mode")
return http.FS(os.DirFS("static"))
}
a.logger.Info("assets loaded in embed mode")
fsys, err := fs.Sub(a.embeds.assets, "static")
if err != nil {
panic(err)
}
return http.FS(fsys)
}
func (a *App) getTemplates(live bool) fs.FS {
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
}