Funcitional
This commit is contained in:
+17
-18
@@ -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)
|
||||
}
|
||||
|
||||
+25
-1445
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user