diff --git a/.golangci.yml b/.golangci.yml index d8824b3..df4e359 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -78,6 +78,13 @@ linters: linters: - errcheck + # Carry-over from cmd/soundtouch-web/handlers relocation: same code, + # same waiver. Tighten in a follow-up if/when the package is reviewed. + - path: pkg/service/soundtouchweb/.*\.go + text: "Error return value of.*is not checked" + linters: + - errcheck + settings: errcheck: check-type-assertions: true diff --git a/cmd/soundtouch-web/main.go b/cmd/soundtouch-web/main.go index 4ca8356..0838006 100644 --- a/cmd/soundtouch-web/main.go +++ b/cmd/soundtouch-web/main.go @@ -12,11 +12,11 @@ import ( "os" "time" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/handlers" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/webtypes" "github.com/gesellix/bose-soundtouch/pkg/client" "github.com/gesellix/bose-soundtouch/pkg/config" "github.com/gesellix/bose-soundtouch/pkg/discovery" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb/webtypes" "github.com/go-chi/chi/v5" "github.com/urfave/cli/v2" ) @@ -79,7 +79,7 @@ func main() { } // Create web app without templates (SPA mode) - webApp := handlers.NewWebApp() + webApp := soundtouchweb.NewWebApp() // Initialize discovery service cfg, err := config.LoadFromEnv() @@ -216,7 +216,7 @@ func resolveBindAddr(bindAddr string) (string, error) { // tell apart entries that came from --devices from those found via // mDNS/UPnP. If the host is already known, the existing entry's // LastSeen is bumped and the function returns without re-fetching. -func addDevice(app *handlers.WebApp, host string, port int, source string) { +func addDevice(app *soundtouchweb.WebApp, host string, port int, source string) { // Fast path: skip the network call if we already know this host. if app.TouchDevice(host) { return @@ -247,7 +247,7 @@ func addDevice(app *handlers.WebApp, host string, port int, source string) { log.Printf("Added %s device %s (%s) at %s:%d", source, info.Name, info.Type, host, port) } -func setupRoutes(app *handlers.WebApp, discoveryService *discovery.UnifiedDiscoveryService) *chi.Mux { +func setupRoutes(app *soundtouchweb.WebApp, discoveryService *discovery.UnifiedDiscoveryService) *chi.Mux { r := chi.NewRouter() // Static assets (embedded in binary) @@ -312,7 +312,7 @@ func setupRoutes(app *handlers.WebApp, discoveryService *discovery.UnifiedDiscov return r } -func discoverDevices(ctx context.Context, app *handlers.WebApp, discoveryService *discovery.UnifiedDiscoveryService) { +func discoverDevices(ctx context.Context, app *soundtouchweb.WebApp, discoveryService *discovery.UnifiedDiscoveryService) { log.Println("Starting device discovery...") devices, err := discoveryService.DiscoverDevices(ctx) diff --git a/cmd/soundtouch-web/spa_test.go b/cmd/soundtouch-web/spa_test.go index 51645c5..8bf13c2 100644 --- a/cmd/soundtouch-web/spa_test.go +++ b/cmd/soundtouch-web/spa_test.go @@ -8,9 +8,9 @@ import ( "strings" "testing" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/handlers" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/webtypes" "github.com/gesellix/bose-soundtouch/pkg/models" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb/webtypes" "github.com/go-chi/chi/v5" ) @@ -99,7 +99,7 @@ func TestSPARouting(t *testing.T) { } func TestAPIEndpoints(t *testing.T) { - app := handlers.NewWebApp() + app := soundtouchweb.NewWebApp() tests := []struct { name string @@ -170,7 +170,7 @@ func TestAPIEndpoints(t *testing.T) { } func TestAPIResponseFormat(t *testing.T) { - app := handlers.NewWebApp() + app := soundtouchweb.NewWebApp() req := httptest.NewRequest("GET", "/api/devices", nil) w := httptest.NewRecorder() @@ -203,7 +203,7 @@ func TestAPIResponseFormat(t *testing.T) { } func TestControlAPIValidation(t *testing.T) { - app := handlers.NewWebApp() + app := soundtouchweb.NewWebApp() tests := []struct { name string @@ -296,7 +296,7 @@ func TestControlAPIValidation(t *testing.T) { } func TestWebSocketUpgrade(t *testing.T) { - app := handlers.NewWebApp() + app := soundtouchweb.NewWebApp() // Test WebSocket upgrade request req := httptest.NewRequest("GET", "/ws", nil) @@ -316,7 +316,7 @@ func TestWebSocketUpgrade(t *testing.T) { } func TestJSONAPIConsistency(t *testing.T) { - app := handlers.NewWebApp() + app := soundtouchweb.NewWebApp() endpoints := []string{ "/api/devices", diff --git a/cmd/soundtouch-web/handlers/handlers.go b/pkg/service/soundtouchweb/handler.go similarity index 99% rename from cmd/soundtouch-web/handlers/handlers.go rename to pkg/service/soundtouchweb/handler.go index a5e4325..0b831e4 100644 --- a/cmd/soundtouch-web/handlers/handlers.go +++ b/pkg/service/soundtouchweb/handler.go @@ -1,5 +1,5 @@ -// Package handlers contains HTTP handlers for the SoundTouch web UI. -package handlers +// Package soundtouchweb contains HTTP handlers for the SoundTouch web UI. +package soundtouchweb import ( "encoding/json" @@ -11,9 +11,9 @@ import ( "sync" "time" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/webtypes" "github.com/gesellix/bose-soundtouch/pkg/models" bmxpkg "github.com/gesellix/bose-soundtouch/pkg/service/bmx" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb/webtypes" "github.com/go-chi/chi/v5" "github.com/gorilla/websocket" ) diff --git a/cmd/soundtouch-web/handlers/handlers_test.go b/pkg/service/soundtouchweb/handler_test.go similarity index 99% rename from cmd/soundtouch-web/handlers/handlers_test.go rename to pkg/service/soundtouchweb/handler_test.go index 4b06af7..564e2ea 100644 --- a/cmd/soundtouch-web/handlers/handlers_test.go +++ b/pkg/service/soundtouchweb/handler_test.go @@ -1,5 +1,5 @@ // Package handlers contains tests for HTTP handlers. -package handlers +package soundtouchweb import ( "context" @@ -10,9 +10,9 @@ import ( "testing" "time" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/webtypes" "github.com/gesellix/bose-soundtouch/pkg/client" "github.com/gesellix/bose-soundtouch/pkg/models" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb/webtypes" "github.com/go-chi/chi/v5" ) diff --git a/cmd/soundtouch-web/handlers/registry_test.go b/pkg/service/soundtouchweb/registry_test.go similarity index 97% rename from cmd/soundtouch-web/handlers/registry_test.go rename to pkg/service/soundtouchweb/registry_test.go index 75a67c4..e014c6e 100644 --- a/cmd/soundtouch-web/handlers/registry_test.go +++ b/pkg/service/soundtouchweb/registry_test.go @@ -1,15 +1,15 @@ // Package handlers contains tests for the device registry API on // WebApp (GetDevice, AddDevice, TouchDevice, DeviceSnapshot, // DeviceCount). -package handlers +package soundtouchweb import ( "fmt" "sync" "testing" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/webtypes" "github.com/gesellix/bose-soundtouch/pkg/models" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb/webtypes" ) func newRegistryDevice(name string) *webtypes.DeviceConnection { diff --git a/cmd/soundtouch-web/static/img/tunein-dark.svg b/pkg/service/soundtouchweb/static/img/tunein-dark.svg similarity index 100% rename from cmd/soundtouch-web/static/img/tunein-dark.svg rename to pkg/service/soundtouchweb/static/img/tunein-dark.svg diff --git a/cmd/soundtouch-web/static/img/tunein-mono.svg b/pkg/service/soundtouchweb/static/img/tunein-mono.svg similarity index 100% rename from cmd/soundtouch-web/static/img/tunein-mono.svg rename to pkg/service/soundtouchweb/static/img/tunein-mono.svg diff --git a/cmd/soundtouch-web/handlers/websocket.go b/pkg/service/soundtouchweb/websocket.go similarity index 98% rename from cmd/soundtouch-web/handlers/websocket.go rename to pkg/service/soundtouchweb/websocket.go index ceac73e..0771e6c 100644 --- a/cmd/soundtouch-web/handlers/websocket.go +++ b/pkg/service/soundtouchweb/websocket.go @@ -1,5 +1,5 @@ -// Package handlers contains WebSocket handlers for real-time communication. -package handlers +// Package soundtouchweb contains WebSocket handlers for real-time communication. +package soundtouchweb import ( "encoding/json" @@ -7,8 +7,8 @@ import ( "net/http" "time" - "github.com/gesellix/bose-soundtouch/cmd/soundtouch-web/webtypes" "github.com/gesellix/bose-soundtouch/pkg/models" + "github.com/gesellix/bose-soundtouch/pkg/service/soundtouchweb/webtypes" "github.com/go-chi/chi/v5" "github.com/gorilla/websocket" ) diff --git a/cmd/soundtouch-web/webtypes/status_test.go b/pkg/service/soundtouchweb/webtypes/status_test.go similarity index 100% rename from cmd/soundtouch-web/webtypes/status_test.go rename to pkg/service/soundtouchweb/webtypes/status_test.go diff --git a/cmd/soundtouch-web/webtypes/types.go b/pkg/service/soundtouchweb/webtypes/types.go similarity index 100% rename from cmd/soundtouch-web/webtypes/types.go rename to pkg/service/soundtouchweb/webtypes/types.go diff --git a/cmd/soundtouch-web/webtypes/types_test.go b/pkg/service/soundtouchweb/webtypes/types_test.go similarity index 100% rename from cmd/soundtouch-web/webtypes/types_test.go rename to pkg/service/soundtouchweb/webtypes/types_test.go