diff --git a/clients/clients.go b/clients/clients.go index 50a589c..7856a62 100644 --- a/clients/clients.go +++ b/clients/clients.go @@ -124,7 +124,7 @@ resp, err := h.client.Do(req) if err != nil { return nil, fmt.Errorf("http %s %s: %w", req.Method, req.URL.Path, err) } -defer resp.Body.Close() +defer func() { _ = resp.Body.Close() }() buf := getBuf() defer putBuf(buf) @@ -420,7 +420,6 @@ type MilvusClient struct { Host string Port int Collection string -connected bool } // NewMilvusClient creates a Milvus client. diff --git a/clients/clients_test.go b/clients/clients_test.go index bb87404..0406552 100644 --- a/clients/clients_test.go +++ b/clients/clients_test.go @@ -90,14 +90,14 @@ func TestEmbeddingsClient_Embed(t *testing.T) { t.Errorf("method = %s, want POST", r.Method) } var req map[string]any - json.NewDecoder(r.Body).Decode(&req) + _ = json.NewDecoder(r.Body).Decode(&req) input, _ := req["input"].([]any) if len(input) != 2 { t.Errorf("input len = %d, want 2", len(input)) } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "data": []map[string]any{ {"embedding": []float64{0.1, 0.2, 0.3}}, {"embedding": []float64{0.4, 0.5, 0.6}}, @@ -121,7 +121,7 @@ func TestEmbeddingsClient_Embed(t *testing.T) { func TestEmbeddingsClient_EmbedSingle(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "data": []map[string]any{ {"embedding": []float64{1.0, 2.0}}, }, @@ -141,7 +141,7 @@ func TestEmbeddingsClient_EmbedSingle(t *testing.T) { func TestEmbeddingsClient_EmbedEmpty(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{"data": []any{}}) + _ = json.NewEncoder(w).Encode(map[string]any{"data": []any{}}) })) defer ts.Close() @@ -175,11 +175,11 @@ func TestEmbeddingsClient_Health(t *testing.T) { func TestRerankerClient_Rerank(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req map[string]any - json.NewDecoder(r.Body).Decode(&req) + _ = json.NewDecoder(r.Body).Decode(&req) if req["query"] != "test query" { t.Errorf("query = %v", req["query"]) } - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "results": []map[string]any{ {"index": 1, "relevance_score": 0.95}, {"index": 0, "relevance_score": 0.80}, @@ -207,7 +207,7 @@ func TestRerankerClient_Rerank(t *testing.T) { func TestRerankerClient_RerankFallbackScore(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "results": []map[string]any{ {"index": 0, "score": 0.77, "relevance_score": 0}, // some APIs only set score }, @@ -235,13 +235,13 @@ func TestLLMClient_Generate(t *testing.T) { t.Errorf("path = %q", r.URL.Path) } var req map[string]any - json.NewDecoder(r.Body).Decode(&req) + _ = json.NewDecoder(r.Body).Decode(&req) msgs, _ := req["messages"].([]any) if len(msgs) == 0 { t.Error("no messages in request") } - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{ {"message": map[string]any{"content": "Paris is the capital of France."}}, }, @@ -262,13 +262,13 @@ func TestLLMClient_Generate(t *testing.T) { func TestLLMClient_GenerateWithContext(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req map[string]any - json.NewDecoder(r.Body).Decode(&req) + _ = json.NewDecoder(r.Body).Decode(&req) msgs, _ := req["messages"].([]any) // Should have system + user message if len(msgs) != 2 { t.Errorf("expected 2 messages, got %d", len(msgs)) } - json.NewEncoder(w).Encode(map[string]any{ + _ = json.NewEncoder(w).Encode(map[string]any{ "choices": []map[string]any{ {"message": map[string]any{"content": "answer with context"}}, }, @@ -288,7 +288,7 @@ func TestLLMClient_GenerateWithContext(t *testing.T) { func TestLLMClient_GenerateNoChoices(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{"choices": []any{}}) + _ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{}}) })) defer ts.Close() @@ -312,7 +312,7 @@ func TestTTSClient_Synthesize(t *testing.T) { if r.URL.Query().Get("text") != "hello world" { t.Errorf("text = %q", r.URL.Query().Get("text")) } - w.Write(expected) + _, _ = w.Write(expected) })) defer ts.Close() @@ -331,7 +331,7 @@ func TestTTSClient_SynthesizeWithSpeaker(t *testing.T) { if r.URL.Query().Get("speaker_id") != "alice" { t.Errorf("speaker_id = %q", r.URL.Query().Get("speaker_id")) } - w.Write([]byte{0x01}) + _, _ = w.Write([]byte{0x01}) })) defer ts.Close() @@ -365,7 +365,7 @@ func TestSTTClient_Transcribe(t *testing.T) { t.Errorf("file size = %d, want 100", len(data)) } - json.NewEncoder(w).Encode(map[string]string{"text": "hello world"}) + _ = json.NewEncoder(w).Encode(map[string]string{"text": "hello world"}) })) defer ts.Close() @@ -384,7 +384,7 @@ func TestSTTClient_TranscribeTranslate(t *testing.T) { if r.URL.Path != "/v1/audio/translations" { t.Errorf("path = %q, want /v1/audio/translations", r.URL.Path) } - json.NewEncoder(w).Encode(map[string]string{"text": "translated"}) + _ = json.NewEncoder(w).Encode(map[string]string{"text": "translated"}) })) defer ts.Close() @@ -406,7 +406,7 @@ func TestSTTClient_TranscribeTranslate(t *testing.T) { func TestHTTPError4xx(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(422) - w.Write([]byte(`{"error": "bad input"}`)) + _, _ = w.Write([]byte(`{"error": "bad input"}`)) })) defer ts.Close() @@ -423,7 +423,7 @@ func TestHTTPError4xx(t *testing.T) { func TestHTTPError5xx(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) - w.Write([]byte("internal server error")) + _, _ = w.Write([]byte("internal server error")) })) defer ts.Close() @@ -467,8 +467,8 @@ func TestBuildMessages(t *testing.T) { func BenchmarkPostJSON(b *testing.B) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - io.Copy(io.Discard, r.Body) - w.Write([]byte(`{"ok":true}`)) + _, _ = io.Copy(io.Discard, r.Body) + _, _ = w.Write([]byte(`{"ok":true}`)) })) defer ts.Close() @@ -482,7 +482,7 @@ func BenchmarkPostJSON(b *testing.B) { b.ResetTimer() for b.Loop() { - c.postJSON(ctx, "/test", payload) + _, _ = c.postJSON(ctx, "/test", payload) } } diff --git a/handler/handler_test.go b/handler/handler_test.go index 84a1eb0..9df5f4a 100644 --- a/handler/handler_test.go +++ b/handler/handler_test.go @@ -66,8 +66,8 @@ func TestCallbackRegistration(t *testing.T) { } // Verify setup/teardown work when called directly. - h.onSetup(context.Background()) - h.onTeardown(context.Background()) + _ = h.onSetup(context.Background()) + _ = h.onTeardown(context.Background()) if !setupCalled || !teardownCalled { t.Error("callbacks should have been invoked") } @@ -290,7 +290,7 @@ func BenchmarkWrapTypedHandler(b *testing.B) { h := New("ai.test", cfg) h.OnTypedMessage(func(ctx context.Context, msg *nats.Msg) (any, error) { var req benchReq - msgpack.Unmarshal(msg.Data, &req) + _ = msgpack.Unmarshal(msg.Data, &req) return map[string]any{"ok": true}, nil }) diff --git a/health/health.go b/health/health.go index d2e5284..e3ff3ea 100644 --- a/health/health.go +++ b/health/health.go @@ -8,7 +8,6 @@ import ( "log/slog" "net" "net/http" - "sync/atomic" "time" ) @@ -22,7 +21,6 @@ type Server struct { readyPath string readyCheck ReadyFunc srv *http.Server - ready atomic.Bool } // New creates a health server on the given port. diff --git a/health/health_test.go b/health/health_test.go index 2d4f963..2c00497 100644 --- a/health/health_test.go +++ b/health/health_test.go @@ -19,7 +19,7 @@ func TestHealthEndpoint(t *testing.T) { if err != nil { t.Fatalf("health request failed: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != 200 { t.Errorf("expected 200, got %d", resp.StatusCode) @@ -42,7 +42,7 @@ func TestReadyEndpointDefault(t *testing.T) { if err != nil { t.Fatalf("ready request failed: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != 200 { t.Errorf("expected 200, got %d", resp.StatusCode) @@ -60,7 +60,7 @@ func TestReadyEndpointNotReady(t *testing.T) { if err != nil { t.Fatalf("ready request failed: %v", err) } - resp.Body.Close() + _ = resp.Body.Close() if resp.StatusCode != 503 { t.Errorf("expected 503 when not ready, got %d", resp.StatusCode) } @@ -70,7 +70,7 @@ func TestReadyEndpointNotReady(t *testing.T) { if err != nil { t.Fatalf("ready request failed: %v", err) } - resp2.Body.Close() + _ = resp2.Body.Close() if resp2.StatusCode != 200 { t.Errorf("expected 200 when ready, got %d", resp2.StatusCode) } diff --git a/messages/bench_test.go b/messages/bench_test.go index 7310641..ee107dd 100644 --- a/messages/bench_test.go +++ b/messages/bench_test.go @@ -178,7 +178,7 @@ func BenchmarkEncode_ChatRequest_MsgpackMap(b *testing.B) { data := chatRequestMap() b.ResetTimer() for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -186,7 +186,7 @@ func BenchmarkEncode_ChatRequest_MsgpackStruct(b *testing.B) { data := chatRequestStruct() b.ResetTimer() for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -194,7 +194,7 @@ func BenchmarkEncode_ChatRequest_Protobuf(b *testing.B) { data := chatRequestProto() b.ResetTimer() for b.Loop() { - proto.Marshal(data) + _, _ = proto.Marshal(data) } } @@ -202,7 +202,7 @@ func BenchmarkEncode_VoiceResponse_MsgpackMap(b *testing.B) { data := voiceResponseMap() b.ResetTimer() for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -210,7 +210,7 @@ func BenchmarkEncode_VoiceResponse_MsgpackStruct(b *testing.B) { data := voiceResponseStruct() b.ResetTimer() for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -218,7 +218,7 @@ func BenchmarkEncode_VoiceResponse_Protobuf(b *testing.B) { data := voiceResponseProto() b.ResetTimer() for b.Loop() { - proto.Marshal(data) + _, _ = proto.Marshal(data) } } @@ -226,7 +226,7 @@ func BenchmarkEncode_TTSChunk_MsgpackMap(b *testing.B) { data := ttsChunkMap() b.ResetTimer() for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -234,7 +234,7 @@ func BenchmarkEncode_TTSChunk_MsgpackStruct(b *testing.B) { data := ttsChunkStruct() b.ResetTimer() for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -242,7 +242,7 @@ func BenchmarkEncode_TTSChunk_Protobuf(b *testing.B) { data := ttsChunkProto() b.ResetTimer() for b.Loop() { - proto.Marshal(data) + _, _ = proto.Marshal(data) } } @@ -255,7 +255,7 @@ func BenchmarkDecode_ChatRequest_MsgpackMap(b *testing.B) { b.ResetTimer() for b.Loop() { var m map[string]any - msgpack.Unmarshal(encoded, &m) + _ = msgpack.Unmarshal(encoded, &m) } } @@ -264,7 +264,7 @@ func BenchmarkDecode_ChatRequest_MsgpackStruct(b *testing.B) { b.ResetTimer() for b.Loop() { var m ChatRequest - msgpack.Unmarshal(encoded, &m) + _ = msgpack.Unmarshal(encoded, &m) } } @@ -273,7 +273,7 @@ func BenchmarkDecode_ChatRequest_Protobuf(b *testing.B) { b.ResetTimer() for b.Loop() { var m pb.ChatRequest - proto.Unmarshal(encoded, &m) + _ = proto.Unmarshal(encoded, &m) } } @@ -282,7 +282,7 @@ func BenchmarkDecode_VoiceResponse_MsgpackMap(b *testing.B) { b.ResetTimer() for b.Loop() { var m map[string]any - msgpack.Unmarshal(encoded, &m) + _ = msgpack.Unmarshal(encoded, &m) } } @@ -291,7 +291,7 @@ func BenchmarkDecode_VoiceResponse_MsgpackStruct(b *testing.B) { b.ResetTimer() for b.Loop() { var m VoiceResponse - msgpack.Unmarshal(encoded, &m) + _ = msgpack.Unmarshal(encoded, &m) } } @@ -300,7 +300,7 @@ func BenchmarkDecode_VoiceResponse_Protobuf(b *testing.B) { b.ResetTimer() for b.Loop() { var m pb.VoiceResponse - proto.Unmarshal(encoded, &m) + _ = proto.Unmarshal(encoded, &m) } } @@ -309,7 +309,7 @@ func BenchmarkDecode_TTSChunk_MsgpackMap(b *testing.B) { b.ResetTimer() for b.Loop() { var m map[string]any - msgpack.Unmarshal(encoded, &m) + _ = msgpack.Unmarshal(encoded, &m) } } @@ -318,7 +318,7 @@ func BenchmarkDecode_TTSChunk_MsgpackStruct(b *testing.B) { b.ResetTimer() for b.Loop() { var m TTSAudioChunk - msgpack.Unmarshal(encoded, &m) + _ = msgpack.Unmarshal(encoded, &m) } } @@ -327,7 +327,7 @@ func BenchmarkDecode_TTSChunk_Protobuf(b *testing.B) { b.ResetTimer() for b.Loop() { var m pb.TTSAudioChunk - proto.Unmarshal(encoded, &m) + _ = proto.Unmarshal(encoded, &m) } } @@ -341,7 +341,7 @@ func BenchmarkRoundtrip_ChatRequest_MsgpackMap(b *testing.B) { for b.Loop() { enc, _ := msgpack.Marshal(data) var dec map[string]any - msgpack.Unmarshal(enc, &dec) + _ = msgpack.Unmarshal(enc, &dec) } } @@ -351,7 +351,7 @@ func BenchmarkRoundtrip_ChatRequest_MsgpackStruct(b *testing.B) { for b.Loop() { enc, _ := msgpack.Marshal(data) var dec ChatRequest - msgpack.Unmarshal(enc, &dec) + _ = msgpack.Unmarshal(enc, &dec) } } @@ -361,7 +361,7 @@ func BenchmarkRoundtrip_ChatRequest_Protobuf(b *testing.B) { for b.Loop() { enc, _ := proto.Marshal(data) var dec pb.ChatRequest - proto.Unmarshal(enc, &dec) + _ = proto.Unmarshal(enc, &dec) } } diff --git a/natsutil/natsutil_test.go b/natsutil/natsutil_test.go index afb663f..6898a52 100644 --- a/natsutil/natsutil_test.go +++ b/natsutil/natsutil_test.go @@ -200,7 +200,7 @@ func BenchmarkEncodeMap(b *testing.B) { "top_k": 10, } for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -212,7 +212,7 @@ func BenchmarkEncodeStruct(b *testing.B) { Active: true, } for b.Loop() { - msgpack.Marshal(data) + _, _ = msgpack.Marshal(data) } } @@ -226,7 +226,7 @@ func BenchmarkDecodeMap(b *testing.B) { }) for b.Loop() { var m map[string]any - msgpack.Unmarshal(raw, &m) + _ = msgpack.Unmarshal(raw, &m) } } @@ -239,7 +239,7 @@ func BenchmarkDecodeStruct(b *testing.B) { }) for b.Loop() { var m testMessage - msgpack.Unmarshal(raw, &m) + _ = msgpack.Unmarshal(raw, &m) } } @@ -251,6 +251,6 @@ func BenchmarkDecodeAudio32KB(b *testing.B) { }) for b.Loop() { var m audioMessage - msgpack.Unmarshal(raw, &m) + _ = msgpack.Unmarshal(raw, &m) } }