Funcitional

This commit is contained in:
Martino Ferrari
2026-05-18 18:07:01 +02:00
parent ed5d381d32
commit 06500d5399
2 changed files with 42 additions and 1463 deletions
+17 -18
View File
@@ -3,11 +3,16 @@ package main
import (
"embed"
"flag"
"fmt"
"io/fs"
"log"
"net/http"
)
//go:embed static/index.html
// version is set at build time via -ldflags "-X main.version=..."
var version = "dev"
//go:embed static
var staticFiles embed.FS
func main() {
@@ -22,25 +27,19 @@ func main() {
udpClient := NewUDPClient(*streamerAddr, *clientPort, hub)
go udpClient.Run()
// Serve the embedded index.html at /.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
data, err := staticFiles.ReadFile("static/index.html")
if err != nil {
http.Error(w, "index.html not found", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(data)
// Serve the embedded static/ directory (index.html, style.css, app.js).
sub, err := fs.Sub(staticFiles, "static")
if err != nil {
log.Fatalf("static sub-fs: %v", err)
}
http.Handle("/", http.FileServer(http.FS(sub)))
http.HandleFunc("/ws", hub.HandleWebSocket)
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, version)
})
http.HandleFunc("/ws", hub.HandleWebSocket)
log.Printf("WebUI listening on %s (streamer=%s, local UDP port=%d)",
*listenAddr, *streamerAddr, *clientPort)
log.Printf("WebUI listening on %s (streamer=%s, local UDP port=%d, version=%s)",
*listenAddr, *streamerAddr, *clientPort, version)
if err := http.ListenAndServe(*listenAddr, nil); err != nil {
log.Fatalf("http: %v", err)
}
File diff suppressed because it is too large Load Diff