|
|
|
@@ -8,6 +8,7 @@ import ( |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"io/fs" |
|
|
|
"log" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
@@ -53,14 +54,15 @@ func loadConfig(path string) (Config, error) { |
|
|
|
// ── Server ──────────────────────────────────────────────────────────────────── |
|
|
|
|
|
|
|
type Server struct { |
|
|
|
cfg Config |
|
|
|
wa *winamp.Controller |
|
|
|
kl *killist.KillList |
|
|
|
hub *hub |
|
|
|
mux *http.ServeMux |
|
|
|
cfg Config |
|
|
|
wa *winamp.Controller |
|
|
|
kl *killist.KillList |
|
|
|
hub *hub |
|
|
|
mux *http.ServeMux |
|
|
|
staticFS fs.FS |
|
|
|
} |
|
|
|
|
|
|
|
func New(configPath string) (*Server, error) { |
|
|
|
func New(configPath string, staticFS fs.FS) (*Server, error) { |
|
|
|
cfg, err := loadConfig(configPath) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("config: %w", err) |
|
|
|
@@ -69,7 +71,7 @@ func New(configPath string) (*Server, error) { |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("killist: %w", err) |
|
|
|
} |
|
|
|
s := &Server{cfg: cfg, wa: winamp.New(), kl: kl, mux: http.NewServeMux()} |
|
|
|
s := &Server{cfg: cfg, wa: winamp.New(), kl: kl, mux: http.NewServeMux(), staticFS: staticFS} |
|
|
|
s.hub = newHub(s.handleCommand) |
|
|
|
s.routes() |
|
|
|
return s, nil |
|
|
|
@@ -90,7 +92,7 @@ func (s *Server) Run() error { |
|
|
|
// ── Routes ──────────────────────────────────────────────────────────────────── |
|
|
|
|
|
|
|
func (s *Server) routes() { |
|
|
|
s.mux.Handle("/", http.FileServer(http.Dir("web/static"))) |
|
|
|
s.mux.Handle("/", http.FileServer(http.FS(s.staticFS))) |
|
|
|
|
|
|
|
// WebSocket (primary interface) |
|
|
|
s.mux.HandleFunc("/ws", s.handleWS) |
|
|
|
|