2023-04-13 00:07:08 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2023-04-28 23:16:58 +02:00
|
|
|
"errors"
|
2023-04-13 00:07:08 +02:00
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-04-26 23:11:58 +02:00
|
|
|
func (a *App) getAssets() http.FileSystem {
|
2023-05-03 02:18:29 +02:00
|
|
|
live := a.setting.IsLive()
|
2023-04-26 23:11:58 +02:00
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
if live {
|
2023-04-19 05:30:52 +02:00
|
|
|
a.logger.Info("assets loaded in live mode")
|
|
|
|
|
2023-04-28 23:16:58 +02:00
|
|
|
_, 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))
|
2023-04-13 00:07:08 +02:00
|
|
|
}
|
|
|
|
|
2023-04-19 05:30:52 +02:00
|
|
|
a.logger.Info("assets loaded in embed mode")
|
2023-04-13 00:07:08 +02:00
|
|
|
|
2023-04-26 22:44:18 +02:00
|
|
|
fsys, err := fs.Sub(a.embeds.assets, "assets")
|
2023-04-13 00:07:08 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.FS(fsys)
|
|
|
|
}
|
|
|
|
|
2023-04-26 23:11:58 +02:00
|
|
|
func (a *App) getTemplates() fs.FS {
|
2023-05-03 02:18:29 +02:00
|
|
|
live := a.setting.IsLive()
|
2023-04-26 23:11:58 +02:00
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
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-28 23:16:58 +02:00
|
|
|
_, err := os.ReadDir(a.templatesPath)
|
2023-04-13 00:07:08 +02:00
|
|
|
if err != nil {
|
2023-04-28 23:16:58 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-04-28 23:16:58 +02:00
|
|
|
return os.DirFS(a.templatesPath)
|
2023-04-13 00:07:08 +02:00
|
|
|
}
|
|
|
|
|
2023-04-19 05:30:52 +02:00
|
|
|
a.logger.Info("templates loaded in embed mode")
|
2023-04-13 00:07:08 +02:00
|
|
|
|
|
|
|
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"))
|
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
return fsys
|
|
|
|
}
|