leo
c4d0cb209b
All checks were successful
continuous-integration/drone/push Build is passing
* let the settings struct be the single source of truth * rm app fields that are covered by settings * pass around a pointer to settings instead of config * consolidate config+flags into settings on start-up * update tests * rm empty settings.go file fixes #4
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func (a *App) getAssets() http.FileSystem {
|
|
live := a.setting.IsLive()
|
|
|
|
if live {
|
|
a.logger.Info("assets loaded in live mode")
|
|
|
|
_, err := os.ReadDir(a.assetsPath)
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
a.Logger().Error("assets dir does not exist")
|
|
} else if errors.Is(err, os.ErrPermission) {
|
|
a.Logger().Error("assets dir is not accessible, check permissions")
|
|
}
|
|
|
|
panic(err)
|
|
}
|
|
|
|
return http.FS(os.DirFS(a.assetsPath))
|
|
}
|
|
|
|
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.setting.IsLive()
|
|
|
|
if live {
|
|
a.logger.Info("templates loaded in live mode")
|
|
|
|
_, err := os.ReadDir(a.templatesPath)
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
a.Logger().Error("templates dir does not exist")
|
|
} else if errors.Is(err, os.ErrPermission) {
|
|
a.Logger().Error("templates dir is not accessible, check permissions")
|
|
}
|
|
|
|
panic(err)
|
|
}
|
|
|
|
return os.DirFS(a.templatesPath)
|
|
}
|
|
|
|
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
|
|
}
|