Funcitional
This commit is contained in:
+15
-16
@@ -3,11 +3,16 @@ package main
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"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
|
var staticFiles embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -22,25 +27,19 @@ func main() {
|
|||||||
udpClient := NewUDPClient(*streamerAddr, *clientPort, hub)
|
udpClient := NewUDPClient(*streamerAddr, *clientPort, hub)
|
||||||
go udpClient.Run()
|
go udpClient.Run()
|
||||||
|
|
||||||
// Serve the embedded index.html at /.
|
// Serve the embedded static/ directory (index.html, style.css, app.js).
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
sub, err := fs.Sub(staticFiles, "static")
|
||||||
if r.URL.Path != "/" {
|
|
||||||
http.NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data, err := staticFiles.ReadFile("static/index.html")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "index.html not found", http.StatusInternalServerError)
|
log.Fatalf("static sub-fs: %v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
http.Handle("/", http.FileServer(http.FS(sub)))
|
||||||
w.Write(data)
|
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, version=%s)",
|
||||||
|
*listenAddr, *streamerAddr, *clientPort, version)
|
||||||
log.Printf("WebUI listening on %s (streamer=%s, local UDP port=%d)",
|
|
||||||
*listenAddr, *streamerAddr, *clientPort)
|
|
||||||
if err := http.ListenAndServe(*listenAddr, nil); err != nil {
|
if err := http.ListenAndServe(*listenAddr, nil); err != nil {
|
||||||
log.Fatalf("http: %v", err)
|
log.Fatalf("http: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-1443
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user