From 662e5d09ec5c05f51c1dd1fc10f10b2f1b713cbf Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Thu, 31 Oct 2024 16:50:08 -0400 Subject: [PATCH] Fix lint --- pkg/gordio/alerting/alerting.go | 11 +++++++---- pkg/gordio/alerting/simulate.go | 10 ++++++++-- pkg/gordio/nexus/client.go | 2 +- pkg/gordio/nexus/commands.go | 6 +++--- pkg/gordio/nexus/websocket.go | 2 +- pkg/gordio/notify/notify.go | 1 - pkg/gordio/server/logging.go | 1 + pkg/gordio/server/routes.go | 2 +- pkg/gordio/server/server.go | 2 -- 9 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pkg/gordio/alerting/alerting.go b/pkg/gordio/alerting/alerting.go index 13e88c9..c8bb5c3 100644 --- a/pkg/gordio/alerting/alerting.go +++ b/pkg/gordio/alerting/alerting.go @@ -120,7 +120,10 @@ func New(cfg config.Alerting, opts ...AlertOption) Alerter { // Go is the alerting loop. It does not start a goroutine. func (as *alerter) Go(ctx context.Context) { - as.startBackfill(ctx) + err := as.startBackfill(ctx) + if err != nil { + log.Error().Err(err).Msg("backfill") + } as.score(time.Now()) ticker := time.NewTicker(alerterTickInterval) @@ -179,7 +182,7 @@ func (as *alerter) testNotifyHandler(w http.ResponseWriter, r *http.Request) { return } - w.Write([]byte("Sent")) + _, _ = w.Write([]byte("Sent")) } // packedScoredTGs gets a packed list of TG IDs for DB use. @@ -323,9 +326,9 @@ func (as *alerter) startBackfill(ctx context.Context) error { log.Debug().Time("since", since).Msg("starting stats backfill") count, err := as.backfill(ctx, since, now) if err != nil { - return fmt.Errorf("backfill failed: %w", err) + return err } - log.Debug().Int("callsCount", count).Str("in", time.Now().Sub(now).String()).Int("tgCount", as.scorer.Score().Len()).Msg("backfill finished") + log.Debug().Int("callsCount", count).Str("in", time.Since(now).String()).Int("tgCount", as.scorer.Score().Len()).Msg("backfill finished") return nil } diff --git a/pkg/gordio/alerting/simulate.go b/pkg/gordio/alerting/simulate.go index 445e33c..8f1f4a9 100644 --- a/pkg/gordio/alerting/simulate.go +++ b/pkg/gordio/alerting/simulate.go @@ -77,7 +77,10 @@ func (s *Simulation) Simulate(ctx context.Context) trending.Scores[cl.Talkgroup] sinceLookback := time.Time(scoreEnd).Add(-24 * time.Hour * time.Duration(s.LookbackDays)) // backfill from lookback start until score start - s.backfill(ctx, sinceLookback, time.Time(s.ScoreStart)) + _, err := s.backfill(ctx, sinceLookback, time.Time(s.ScoreStart)) + if err != nil { + log.Error().Err(err).Msg("simulate backfill") + } // initial score s.scores = s.scorer.Score() @@ -94,7 +97,10 @@ func (s *Simulation) Simulate(ctx context.Context) trending.Scores[cl.Talkgroup] // compute time since score start until now // backfill from scorestart until now. sim is enabled, so scoring will be done by stepClock() - s.backfill(ctx, time.Time(s.ScoreStart), scoreEnd) + _, err = s.backfill(ctx, time.Time(s.ScoreStart), scoreEnd) + if err != nil { + log.Error().Err(err).Msg("simulate backfill final") + } s.lastScore = scoreEnd sort.Sort(s.scores) diff --git a/pkg/gordio/nexus/client.go b/pkg/gordio/nexus/client.go index 239b0d6..6366578 100644 --- a/pkg/gordio/nexus/client.go +++ b/pkg/gordio/nexus/client.go @@ -92,7 +92,7 @@ func pbServerInfo(ctx context.Context) *pb.ServerInfo { } func (c *client) Hello(ctx context.Context) { - c.Send(&pb.Message{ + _ = c.Send(&pb.Message{ ToClientMessage: &pb.Message_Hello{ Hello: &pb.Hello{ ServerInfo: pbServerInfo(ctx), diff --git a/pkg/gordio/nexus/commands.go b/pkg/gordio/nexus/commands.go index b4c1164..b1059d6 100644 --- a/pkg/gordio/nexus/commands.go +++ b/pkg/gordio/nexus/commands.go @@ -57,7 +57,7 @@ func (c *client) SendError(cmd *pb.Command, err error) { }, }, } - c.Send(e) + _ = c.Send(e) } func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error { @@ -73,7 +73,7 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error { var md *structpb.Struct if len(tgi.Metadata) > 0 { m := make(map[string]interface{}) - err := json.Unmarshal(tgi.Metadata, m) + err := json.Unmarshal(tgi.Metadata, &m) if err != nil { log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("unmarshal tg metadata") } @@ -95,7 +95,7 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error { SystemName: tgi.SystemName, } - c.Send(&pb.Message{ + _ = c.Send(&pb.Message{ ToClientMessage: &pb.Message_Response{ Response: &pb.CommandResponse{ CommandId: CommandID(ctx), diff --git a/pkg/gordio/nexus/websocket.go b/pkg/gordio/nexus/websocket.go index d7b7d5c..e69c8a2 100644 --- a/pkg/gordio/nexus/websocket.go +++ b/pkg/gordio/nexus/websocket.go @@ -86,7 +86,7 @@ func (wm *wsManager) serveWS(w http.ResponseWriter, r *http.Request) { } func (conn *wsConn) Shutdown() { - conn.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseGoingAway, ""), time.Now().Add(writeWait)) + _ = conn.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseGoingAway, ""), time.Now().Add(writeWait)) } func (conn *wsConn) readPump(ctx context.Context, reg Registry, c Client) { diff --git a/pkg/gordio/notify/notify.go b/pkg/gordio/notify/notify.go index e073ac7..1207946 100644 --- a/pkg/gordio/notify/notify.go +++ b/pkg/gordio/notify/notify.go @@ -17,7 +17,6 @@ type Notifier interface { type notifier struct { *notify.Notify - cfg []config.NotifyService } func (n *notifier) buildSlackWebhookPayload(cfg config.NotifyService) func(string, string) any { diff --git a/pkg/gordio/server/logging.go b/pkg/gordio/server/logging.go index 4c8502e..602193d 100644 --- a/pkg/gordio/server/logging.go +++ b/pkg/gordio/server/logging.go @@ -156,6 +156,7 @@ func RequestLogger() func(next http.Handler) http.Handler { } } +//nolint:unused const ( colorBlack = iota + 30 colorRed diff --git a/pkg/gordio/server/routes.go b/pkg/gordio/server/routes.go index 19c03d9..0b00455 100644 --- a/pkg/gordio/server/routes.go +++ b/pkg/gordio/server/routes.go @@ -77,7 +77,7 @@ func (s *Server) clientRoute(r chi.Router, clientRoot fs.FS) { func ServerHeaderAdd(next http.Handler) http.Handler { serverString := version.HttpString("gordio") hfn := func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Server", serverString) + w.Header().Set(serverHeader, serverString) next.ServeHTTP(w, r) } return http.HandlerFunc(hfn) diff --git a/pkg/gordio/server/server.go b/pkg/gordio/server/server.go index 444af30..4f54909 100644 --- a/pkg/gordio/server/server.go +++ b/pkg/gordio/server/server.go @@ -47,8 +47,6 @@ func New(ctx context.Context, cfg *config.Config) (*Server, error) { return nil, err } - ctx = database.CtxWithDB(ctx, db) - r := chi.NewRouter() authenticator := auth.NewAuthenticator(cfg.Auth)