-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathembedded_fs_utils.go
More file actions
42 lines (35 loc) · 859 Bytes
/
Copy pathembedded_fs_utils.go
File metadata and controls
42 lines (35 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"embed"
"io/fs"
"os"
"github.com/ericls/imgdd/buildflag"
)
//go:embed httpserver/templates/*.gotmpl
var embeddedTemplates embed.FS
//go:embed web_client/dist/*
var embeddedStatic embed.FS
type moutingFS struct {
Templates fs.FS
Static fs.FS
}
var MoutingFS moutingFS
func init() {
if buildflag.IsDebug {
MoutingFS.Templates = os.DirFS("httpserver/templates")
MoutingFS.Static = os.DirFS("web_client/dist")
} else {
templatesFs, err := fs.Sub(embeddedTemplates, "httpserver/templates")
if err != nil {
println("Error loading embedded templates: ", err.Error())
panic(err)
}
MoutingFS.Templates = templatesFs
staticFs, err := fs.Sub(embeddedStatic, "web_client/dist")
if err != nil {
println("Error loading embedded templates: ", err.Error())
panic(err)
}
MoutingFS.Static = staticFs
}
}