Include static files in build

Building requires replacing symlinks under static/ with the target file
contents.
This commit is contained in:
Jarno Rankinen 2023-02-02 11:44:30 +02:00
parent 48bdfd691b
commit 5d23e34f44
2 changed files with 14 additions and 3 deletions

2
enervent-ctrl-go/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build.sh
build/*

View File

@ -1,13 +1,18 @@
package main
import (
"embed"
"encoding/json"
"io/fs"
"log"
"net/http"
"github.com/0ranki/enervent-ctrl/enervent-ctrl-go/pingvinKL"
)
//go:embed static/html/*
var static embed.FS
var (
version = "0.0.2"
pingvin pingvinKL.PingvinKL
@ -34,9 +39,13 @@ func listen() {
log.Println("Starting pingvinAPI...")
http.HandleFunc("/api/v1/coils/", coils)
http.HandleFunc("/api/v1/registers/", registers)
static := http.FileServer(http.Dir("./static/html"))
http.Handle("/", static)
err := http.ListenAndServe(":8888", nil)
html, err := fs.Sub(static, "static/html")
if err != nil {
log.Fatal(err)
}
htmlroot := http.FileServer(http.FS(html))
http.Handle("/", htmlroot)
err = http.ListenAndServe(":8888", nil)
if err != nil {
log.Fatal(err)
}