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
elChan := make(chan ws.ChanMsg)
go ws.ListenWebsocket(a.conn, a.ctx, elChan)
go ws.ListenWebsocket(a.conn, elChan)
for {
msg, ok := <-elChan

View File

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

View File

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

View File

@@ -1,7 +1,6 @@
package websocket
import (
"context"
"encoding/json"
"log/slog"
@@ -21,7 +20,7 @@ type ChanMsg struct {
Raw []byte
}
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) {
func ListenWebsocket(conn *websocket.Conn, c chan ChanMsg) {
for {
bytes, err := ReadMessage(conn)
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
Success: true,
}
json.Unmarshal(bytes, &base)
_ = json.Unmarshal(bytes, &base)
if !base.Success {
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
json.Unmarshal(msg, &authResp)
// log.Println(authResp.MsgType)
err = json.Unmarshal(msg, &authResp)
if err != nil {
return err
}
if authResp.MsgType != "auth_ok" {
return ErrInvalidToken
}

View File

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