diff options
author | Grail Finder <wohilas@gmail.com> | 2025-05-19 10:42:10 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2025-05-19 10:42:10 +0300 |
commit | 94df5b830c84d1fb570c85ec072d917ea4497d8c (patch) | |
tree | 4ac09beade74f6500641ab067ea9fa82aaa03623 | |
parent | a7e7da6f9965624e4667ecedd23f2eb073ac2f56 (diff) |
Chore: linter
-rw-r--r-- | .golangci.yml | 50 | ||||
-rw-r--r-- | bot.go | 12 | ||||
-rw-r--r-- | extra/audio.go | 17 | ||||
-rw-r--r-- | extra/stt.go | 11 | ||||
-rw-r--r-- | pngmeta/metareader.go | 3 | ||||
-rw-r--r-- | rag/main.go | 2 |
6 files changed, 52 insertions, 43 deletions
diff --git a/.golangci.yml b/.golangci.yml index 66732bf..d377c38 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,32 +1,44 @@ +version: "2" run: - timeout: 1m concurrency: 2 tests: false - linters: - enable-all: false - disable-all: true + default: none enable: + - bodyclose - errcheck - - gosimple + - fatcontext - govet - ineffassign + - noctx + - perfsprint + - prealloc - staticcheck - - typecheck - unused - - prealloc - presets: - - performance - -linters-settings: - funlen: - lines: 80 - statements: 50 - lll: - line-length: 80 - + settings: + funlen: + lines: 80 + statements: 50 + lll: + line-length: 80 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ issues: - exclude: - # Display all issues max-issues-per-linter: 0 max-same-issues: 0 +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ @@ -43,9 +43,10 @@ var ( interruptResp = false ragger *rag.RAG chunkParser ChunkParser - orator extra.Orator - asr extra.STT - defaultLCPProps = map[string]float32{ + //nolint:unused // TTS_ENABLED conditionally uses this + orator extra.Orator + asr extra.STT + defaultLCPProps = map[string]float32{ "temperature": 0.8, "dry_multiplier": 0.0, "min_p": 0.05, @@ -272,6 +273,7 @@ func roleToIcon(role string) string { return "<" + role + ">: " } +// FIXME: it should not be here; move to extra func checkGame(role string, tv *tview.TextView) { // Handle Cluedo game flow // should go before form msg, since formmsg takes chatBody and makes ioreader out of it @@ -283,8 +285,7 @@ func checkGame(role string, tv *tview.TextView) { playerOrder = []string{cfg.UserRole, cfg.AssistantRole, cfg.CluedoRole2} cluedoState = extra.CluedoPrepCards(playerOrder) } - - notifyUser("got in cluedo", "yay") + // notifyUser("got in cluedo", "yay") currentPlayer := playerOrder[0] playerOrder = append(playerOrder[1:], currentPlayer) // Rotate turns if role == cfg.UserRole { @@ -296,7 +297,6 @@ func checkGame(role string, tv *tview.TextView) { }) } } - return } func chatRound(userMsg, role string, tv *tview.TextView, regen, resume bool) { diff --git a/extra/audio.go b/extra/audio.go index 8b0d8f9..fc5e2ba 100644 --- a/extra/audio.go +++ b/extra/audio.go @@ -46,17 +46,12 @@ type KokoroOrator struct { } func stoproutine(orator Orator) { - select { - case <-TTSDoneChan: - orator.GetLogger().Info("orator got done signal") - orator.Stop() - // close(TTSTextChan) - // TTSTextChan = make(chan string, 10000) - // drain the channel - for len(TTSTextChan) > 0 { - <-TTSTextChan - } - return + <-TTSDoneChan + orator.GetLogger().Info("orator got done signal") + orator.Stop() + // drain the channel + for len(TTSTextChan) > 0 { + <-TTSTextChan } } diff --git a/extra/stt.go b/extra/stt.go index 950f7a9..51fd314 100644 --- a/extra/stt.go +++ b/extra/stt.go @@ -32,7 +32,6 @@ type WhisperSTT struct { ServerURL string SampleRate int AudioBuffer *bytes.Buffer - streamer StreamCloser recording bool } @@ -90,7 +89,7 @@ func (stt *WhisperSTT) StopRecording() (string, error) { return "", err } // Send request - resp, err := http.Post("http://localhost:8081/inference", writer.FormDataContentType(), body) + resp, err := http.Post(stt.ServerURL, writer.FormDataContentType(), body) if err != nil { stt.logger.Error("fn: StopRecording", "error", err) return "", err @@ -122,7 +121,9 @@ func (stt *WhisperSTT) writeWavHeader(w io.Writer, dataSize int) { binary.LittleEndian.PutUint16(header[34:36], 16) copy(header[36:40], "data") binary.LittleEndian.PutUint32(header[40:44], uint32(dataSize)) - w.Write(header) + if _, err := w.Write(header); err != nil { + stt.logger.Error("writeWavHeader", "error", err) + } } func (stt *WhisperSTT) IsRecording() bool { @@ -136,7 +137,9 @@ func (stt *WhisperSTT) microphoneStream(sampleRate int) error { in := make([]int16, 64) stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), len(in), in) if err != nil { - portaudio.Terminate() + if paErr := portaudio.Terminate(); paErr != nil { + return fmt.Errorf("failed to open microphone: %w; terminate error: %w", err, paErr) + } return fmt.Errorf("failed to open microphone: %w", err) } go func(stream *portaudio.Stream) { diff --git a/pngmeta/metareader.go b/pngmeta/metareader.go index 408af18..c396b4e 100644 --- a/pngmeta/metareader.go +++ b/pngmeta/metareader.go @@ -22,7 +22,6 @@ const ( writeHeader = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" ) - type PngEmbed struct { Key string Value string @@ -96,7 +95,7 @@ func ReadCard(fname, uname string) (*models.CharCard, error) { return nil, err } if charSpec.Name == "" { - return nil, fmt.Errorf("failed to find role; fname %s\n", fname) + return nil, fmt.Errorf("failed to find role; fname %s", fname) } return charSpec.Simplify(uname, fname), nil } diff --git a/rag/main.go b/rag/main.go index 5e53839..f3028b4 100644 --- a/rag/main.go +++ b/rag/main.go @@ -235,7 +235,7 @@ func (r *RAG) LineToVector(line string) ([]float32, error) { } defer resp.Body.Close() if resp.StatusCode != 200 { - err = fmt.Errorf("non 200 resp; code: %v\n", resp.StatusCode) + err = fmt.Errorf("non 200 resp; code: %v", resp.StatusCode) r.logger.Error(err.Error()) return nil, err } |