diff --git a/main.go b/main.go index 89b078f..970e320 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,32 @@ package main import ( + "io/fs" "log" "net" "net/http" "os" - "git.exozy.me/exozyme/status/scanner" + "embed" + "git.exozy.me/exozyme/status/core" + "git.exozy.me/exozyme/status/scanner" "github.com/cbroglie/mustache" ) -func parseAndRenderTemplate(templateLocation string, data interface{}) (string, error) { - tmpl, err := mustache.ParseFile(templateLocation) +//go:embed all:public +var staticAssets embed.FS + +//go:embed all:templates +var templateAssets embed.FS + +func parseAndRenderTemplate(templateName string, data interface{}) (string, error) { + rawTemplate, err := templateAssets.ReadFile(templateName) + if err != nil { + return "", err + } + + tmpl, err := mustache.ParseString(string(rawTemplate)) if err != nil { log.Println("Failed to parse template:", err) return "", err @@ -72,7 +86,13 @@ func main() { } http.HandleFunc("/", rootPage) - fs := http.FileServer(http.Dir("./public")) + + // serve public folder from embedfs + htmlContent, err := fs.Sub(fs.FS(staticAssets), "public") + if err != nil { + log.Fatal(err) + } + fs := http.FileServer(http.FS(htmlContent)) http.Handle("/public/", http.StripPrefix("/public/", fs)) protocol := "tcp"