fix: resolve wastedassign lint warnings in channel subpackages

Remove wasted initial assignments before switch statements in
onebot (segType), telegram (filename), and wecom (mediaType).
This commit is contained in:
Hoshina 2026-02-26 23:36:06 +08:00
parent 35a035bdda
commit ba98069a00
7 changed files with 8 additions and 13 deletions

View file

@ -192,7 +192,7 @@ func gatewayCmd(debug bool) error {
msgBus.Close() msgBus.Close()
// Use a fresh context with timeout for graceful shutdown, // Use a fresh context with timeout for graceful shutdown,
// since the original ctx is already cancelled. // since the original ctx is already canceled.
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 15*time.Second) shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 15*time.Second)
defer shutdownCancel() defer shutdownCancel()

View file

@ -73,13 +73,13 @@ func TestPublishInbound_ContextCancel(t *testing.T) {
} }
} }
// Now buffer is full; publish with a cancelled context // Now buffer is full; publish with a canceled context
cancelCtx, cancel := context.WithCancel(context.Background()) cancelCtx, cancel := context.WithCancel(context.Background())
cancel() cancel()
err := mb.PublishInbound(cancelCtx, InboundMessage{Content: "overflow"}) err := mb.PublishInbound(cancelCtx, InboundMessage{Content: "overflow"})
if err == nil { if err == nil {
t.Fatal("expected error from cancelled context, got nil") t.Fatal("expected error from canceled context, got nil")
} }
if err != context.Canceled { if err != context.Canceled {
t.Fatalf("expected context.Canceled, got %v", err) t.Fatalf("expected context.Canceled, got %v", err)
@ -115,7 +115,7 @@ func TestConsumeInbound_ContextCancel(t *testing.T) {
_, ok := mb.ConsumeInbound(ctx) _, ok := mb.ConsumeInbound(ctx)
if ok { if ok {
t.Fatal("expected ok=false when context is cancelled") t.Fatal("expected ok=false when context is canceled")
} }
} }

View file

@ -455,7 +455,7 @@ func (m *Manager) runWorker(ctx context.Context, name string, w *channelWorker)
func (m *Manager) sendWithRetry(ctx context.Context, name string, w *channelWorker, msg bus.OutboundMessage) { func (m *Manager) sendWithRetry(ctx context.Context, name string, w *channelWorker, msg bus.OutboundMessage) {
// Rate limit: wait for token // Rate limit: wait for token
if err := w.limiter.Wait(ctx); err != nil { if err := w.limiter.Wait(ctx); err != nil {
// ctx cancelled, shutting down // ctx canceled, shutting down
return return
} }

View file

@ -245,7 +245,7 @@ func TestSendWithRetry_ContextCancelled(t *testing.T) {
m.sendWithRetry(ctx, "test", w, msg) m.sendWithRetry(ctx, "test", w, msg)
// Should have called Send once, then noticed ctx cancelled during backoff // Should have called Send once, then noticed ctx canceled during backoff
if callCount != 1 { if callCount != 1 {
t.Fatalf("expected 1 Send call before context cancellation, got %d", callCount) t.Fatalf("expected 1 Send call before context cancellation, got %d", callCount)
} }

View file

@ -469,7 +469,7 @@ func (c *OneBotChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMess
continue continue
} }
segType := "image" var segType string
switch part.Type { switch part.Type {
case "image": case "image":
segType = "image" segType = "image"

View file

@ -243,11 +243,6 @@ func (c *TelegramChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMe
continue continue
} }
filename := part.Filename
if filename == "" {
filename = "file"
}
switch part.Type { switch part.Type {
case "image": case "image":
params := &telego.SendPhotoParams{ params := &telego.SendPhotoParams{

View file

@ -221,7 +221,7 @@ func (c *WeComAppChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMe
} }
// Map part type to WeCom media type // Map part type to WeCom media type
mediaType := "file" var mediaType string
switch part.Type { switch part.Type {
case "image": case "image":
mediaType = "image" mediaType = "image"