pcmt/app/assets.go

52 lines
933 B
Go
Raw Normal View History

package app
import (
"io/fs"
"net/http"
"os"
)
func (a *App) getAssets(live bool) http.FileSystem {
if live {
2023-04-19 05:30:52 +02:00
a.logger.Info("assets loaded in live mode")
return http.FS(os.DirFS("static"))
}
2023-04-19 05:30:52 +02:00
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 {
2023-04-19 05:30:52 +02:00
a.logger.Info("templates loaded in live mode")
2023-04-19 21:46:56 +02:00
2023-04-19 05:30:52 +02:00
_, err := os.ReadDir("templates")
if err != nil {
2023-04-19 05:30:52 +02:00
a.Logger().Error("templates dir does not exist or is not accessible, check permissions")
panic(err)
}
return os.DirFS("templates")
}
2023-04-19 05:30:52 +02:00
a.logger.Info("templates loaded in embed mode")
fsys, err := fs.Sub(a.embeds.templates, "templates")
if err != nil {
panic(err)
}
2023-04-19 05:30:52 +02:00
// alt:
// func (a *App) getTemplates(live bool) http.FileSystem {
// return http.FS(os.DirFS("../templates"))
return fsys
}