Bundle files with executable
This commit is contained in:
parent
c2a4b7ccfe
commit
8817e433a4
1 changed files with 24 additions and 4 deletions
28
main.go
28
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"
|
||||
|
|
Loading…
Reference in a new issue