use embed.fs wrapper for langFS so lang/ is not needed in paths

[files]lang_files is now the path to the lang directory, not path to a
directory containing it.
This commit is contained in:
Harvey Tindall
2021-02-12 14:35:16 +00:00
parent 98a9e20cc0
commit e6775cd2d1
3 changed files with 23 additions and 11 deletions
+17 -5
View File
@@ -13,18 +13,30 @@ with open("embed.go", "w") as f:
if EMBED in trues:
f.write("""package main
import (
"embed"
"log"
"embed"
"io/fs"
"log"
)
//go:embed data data/html data/web data/web/css data/web/js
var localFS embed.FS
//go:embed lang/common lang/admin lang/email lang/form lang/setup
var langFS embed.FS
var lFS embed.FS
var langFS LangFS
type LangFS struct {
fs embed.FS
}
func (l LangFS) Open(name string) (fs.File, error) { return l.fs.Open("lang/" + name) }
func (l LangFS) ReadDir(name string) ([]fs.DirEntry, error) { return l.fs.ReadDir("lang/" + name) }
func (l LangFS) ReadFile(name string) ([]byte, error) { return l.fs.ReadFile("lang/" + name) }
func loadLocalFS() {
log.Println("Using internal storage")
langFS = LangFS{lFS}
log.Println("Using internal storage")
}""")
elif EMBED in falses:
f.write("""package main
@@ -42,5 +54,5 @@ func loadLocalFS() {
log.Println("Using external storage")
executable, _ := os.Executable()
localFS = os.DirFS(filepath.Dir(executable))
langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data"))
langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data", "lang"))
}""")