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