fix: resolve golangci-lint errcheck warnings
- Add error checks for unchecked return values (errcheck) - Remove unused struct fields (unused) - Fix gofmt formatting issues
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user