refactored view package
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/db"
|
||||
"git.haelnorr.com/h/oslstats/internal/throw"
|
||||
"git.haelnorr.com/h/oslstats/internal/view/component/popup"
|
||||
"git.haelnorr.com/h/oslstats/internal/view/popup"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
"github.com/pkg/errors"
|
||||
@@ -28,36 +28,24 @@ func NotificationWS(
|
||||
}
|
||||
nc, err := setupClient(s, w, r)
|
||||
if err != nil {
|
||||
s.LogError(hws.HWSError{
|
||||
Message: "Failed to get notification client",
|
||||
Error: err,
|
||||
Level: hws.ErrorERROR,
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
})
|
||||
logError(s, "Failed to get notification client", errors.Wrap(err, "setupClient"))
|
||||
return
|
||||
}
|
||||
ws, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
||||
OriginPatterns: []string{cfg.HWSAuth.TrustedHost},
|
||||
})
|
||||
if err != nil {
|
||||
s.LogError(hws.HWSError{
|
||||
Message: "Failed to open websocket",
|
||||
Error: err,
|
||||
Level: hws.ErrorERROR,
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
})
|
||||
logError(s, "Failed to open websocket", errors.Wrap(err, "websocket.Accept"))
|
||||
return
|
||||
}
|
||||
defer ws.CloseNow()
|
||||
ctx := ws.CloseRead(r.Context())
|
||||
err = notifyLoop(ctx, nc, ws)
|
||||
if err != nil {
|
||||
s.LogError(hws.HWSError{
|
||||
Message: "Notification error",
|
||||
Error: err,
|
||||
Level: hws.ErrorERROR,
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
})
|
||||
logError(s, "Notification error", errors.Wrap(err, "notifyLoop"))
|
||||
}
|
||||
err = ws.CloseNow()
|
||||
if err != nil {
|
||||
logError(s, "Error closing websocket", errors.Wrap(err, "ws.CloseNow"))
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user