Fix default golanglint-ci errors

These errors show up when simply running `golangci-lint run ./...` on the project.
This commit is contained in:
Matthias Loibl
2025-01-17 17:59:30 +01:00
parent 02b6c413f1
commit ccebcb869f
6 changed files with 14 additions and 10 deletions

2
app.go
View File

@@ -304,7 +304,7 @@ func (a *App) Start() {
// entity listeners and event listeners // entity listeners and event listeners
elChan := make(chan ws.ChanMsg) elChan := make(chan ws.ChanMsg)
go ws.ListenWebsocket(a.conn, a.ctx, elChan) go ws.ListenWebsocket(a.conn, elChan)
for { for {
msg, ok := <-elChan msg, ok := <-elChan

View File

@@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/golang-module/carbon" "github.com/golang-module/carbon"
"saml.dev/gome-assistant/internal" "saml.dev/gome-assistant/internal"
) )
@@ -193,7 +194,7 @@ func (b elBuilder3) Build() EntityListener {
/* Functions */ /* Functions */
func callEntityListeners(app *App, msgBytes []byte) { func callEntityListeners(app *App, msgBytes []byte) {
msg := stateChangedMsg{} msg := stateChangedMsg{}
json.Unmarshal(msgBytes, &msg) _ = json.Unmarshal(msgBytes, &msg)
data := msg.Event.Data data := msg.Event.Data
eid := data.EntityID eid := data.EntityID
listeners, ok := app.entityListeners[eid] listeners, ok := app.entityListeners[eid]

View File

@@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/golang-module/carbon" "github.com/golang-module/carbon"
"saml.dev/gome-assistant/internal" "saml.dev/gome-assistant/internal"
ws "saml.dev/gome-assistant/internal/websocket" ws "saml.dev/gome-assistant/internal/websocket"
) )
@@ -141,7 +142,7 @@ type BaseEventMsg struct {
/* Functions */ /* Functions */
func callEventListeners(app *App, msg ws.ChanMsg) { func callEventListeners(app *App, msg ws.ChanMsg) {
baseEventMsg := BaseEventMsg{} baseEventMsg := BaseEventMsg{}
json.Unmarshal(msg.Raw, &baseEventMsg) _ = json.Unmarshal(msg.Raw, &baseEventMsg)
listeners, ok := app.eventListeners[baseEventMsg.Event.EventType] listeners, ok := app.eventListeners[baseEventMsg.Event.EventType]
if !ok { if !ok {
// no listeners registered for this event type // no listeners registered for this event type

View File

@@ -1,7 +1,6 @@
package websocket package websocket
import ( import (
"context"
"encoding/json" "encoding/json"
"log/slog" "log/slog"
@@ -21,7 +20,7 @@ type ChanMsg struct {
Raw []byte Raw []byte
} }
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) { func ListenWebsocket(conn *websocket.Conn, c chan ChanMsg) {
for { for {
bytes, err := ReadMessage(conn) bytes, err := ReadMessage(conn)
if err != nil { if err != nil {
@@ -34,7 +33,7 @@ func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg)
// default to true for messages that don't include "success" at all // default to true for messages that don't include "success" at all
Success: true, Success: true,
} }
json.Unmarshal(bytes, &base) _ = json.Unmarshal(bytes, &base)
if !base.Success { if !base.Success {
slog.Warn("Received unsuccessful response", "response", string(bytes)) slog.Warn("Received unsuccessful response", "response", string(bytes))
} }

View File

@@ -114,8 +114,10 @@ func VerifyAuthResponse(conn *websocket.Conn, ctx context.Context) error {
} }
var authResp authResponse var authResp authResponse
json.Unmarshal(msg, &authResp) err = json.Unmarshal(msg, &authResp)
// log.Println(authResp.MsgType) if err != nil {
return err
}
if authResp.MsgType != "auth_ok" { if authResp.MsgType != "auth_ok" {
return ErrInvalidToken return ErrInvalidToken
} }

View File

@@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/golang-module/carbon" "github.com/golang-module/carbon"
"saml.dev/gome-assistant/internal/http" "saml.dev/gome-assistant/internal/http"
) )
@@ -69,8 +70,8 @@ func (s *StateImpl) Get(entityId string) (EntityState, error) {
return EntityState{}, err return EntityState{}, err
} }
es := EntityState{} es := EntityState{}
json.Unmarshal(resp, &es) err = json.Unmarshal(resp, &es)
return es, nil return es, err
} }
func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) { func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) {