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:
12
e2e_test.go
12
e2e_test.go
@@ -150,12 +150,12 @@ func TestTranscriptionE2E_MockWhisper(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("missing 'file' field: %v", err)
|
t.Errorf("missing 'file' field: %v", err)
|
||||||
} else {
|
} else {
|
||||||
file.Close()
|
_ = file.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]string{"text": "hello world"})
|
_ = json.NewEncoder(w).Encode(map[string]string{"text": "hello world"})
|
||||||
}))
|
}))
|
||||||
defer whisperSrv.Close()
|
defer whisperSrv.Close()
|
||||||
|
|
||||||
@@ -166,20 +166,20 @@ func TestTranscriptionE2E_MockWhisper(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
part.Write(make([]byte, 8000)) // simulated audio
|
_, _ = part.Write(make([]byte, 8000)) // simulated audio
|
||||||
writer.Close()
|
_ = writer.Close()
|
||||||
|
|
||||||
resp, err := http.Post(whisperSrv.URL+"/v1/audio/transcriptions", writer.FormDataContentType(), &buf)
|
resp, err := http.Post(whisperSrv.URL+"/v1/audio/transcriptions", writer.FormDataContentType(), &buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("status = %d", resp.StatusCode)
|
t.Errorf("status = %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
var result map[string]string
|
var result map[string]string
|
||||||
json.NewDecoder(resp.Body).Decode(&result)
|
_ = json.NewDecoder(resp.Body).Decode(&result)
|
||||||
if result["text"] != "hello world" {
|
if result["text"] != "hello world" {
|
||||||
t.Errorf("text = %q, want %q", result["text"], "hello world")
|
t.Errorf("text = %q, want %q", result["text"], "hello world")
|
||||||
}
|
}
|
||||||
|
|||||||
10
main.go
10
main.go
@@ -264,8 +264,8 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
part.Write(audioData)
|
_, _ = part.Write(audioData)
|
||||||
w.Close()
|
_ = w.Close()
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, whisperURL+"/v1/audio/transcriptions", &buf)
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, whisperURL+"/v1/audio/transcriptions", &buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -277,7 +277,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("whisper request: %w", err)
|
return "", fmt.Errorf("whisper request: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
@@ -335,7 +335,7 @@ func main() {
|
|||||||
State: state,
|
State: state,
|
||||||
}
|
}
|
||||||
packed, _ := msgpack.Marshal(result)
|
packed, _ := msgpack.Marshal(result)
|
||||||
nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed)
|
_ = nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed)
|
||||||
slog.Info("published transcription", "session", sessionID, "seq", seq)
|
slog.Info("published transcription", "session", sessionID, "seq", seq)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,7 +448,7 @@ func main() {
|
|||||||
SpeakerID: buffer.speakerID,
|
SpeakerID: buffer.speakerID,
|
||||||
}
|
}
|
||||||
packed, _ := msgpack.Marshal(interruptMsg)
|
packed, _ := msgpack.Marshal(interruptMsg)
|
||||||
nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed)
|
_ = nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed)
|
||||||
slog.Info("published interrupt", "session", sessionID)
|
slog.Info("published interrupt", "session", sessionID)
|
||||||
buffer.setState(stateListening)
|
buffer.setState(stateListening)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func TestTranscribeHTTP(t *testing.T) {
|
|||||||
t.Errorf("expected POST, got %s", r.Method)
|
t.Errorf("expected POST, got %s", r.Method)
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]string{"text": "hello world"})
|
_ = json.NewEncoder(w).Encode(map[string]string{"text": "hello world"})
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ func TestTranscribeHTTP(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("status = %d", resp.StatusCode)
|
t.Errorf("status = %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user