Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for Go Lint Using golangci-lint #135

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/api/live/v1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (

// DefaultCallbackHandler is a default callback handler for live transcription
// Simply prints the transcript to stdout
type DefaultCallbackHandler struct {
sb strings.Builder
}
type DefaultCallbackHandler struct{}

// NewDefaultCallbackHandler creates a new DefaultCallbackHandler
func NewDefaultCallbackHandler() DefaultCallbackHandler {
Expand Down
12 changes: 8 additions & 4 deletions pkg/audio/microphone/microphone.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ import (

// Initialize inits the library
func Initialize() {
portaudio.Initialize()
err := portaudio.Initialize()
if err != nil {
klog.V(1).Printf("portaudio.Initialize failed. Err: %v\n", err)
}
}

// Teardown cleans up the library
func Teardown() {
portaudio.Terminate()
err := portaudio.Terminate()
if err != nil {
klog.V(1).Printf("portaudio.Terminate failed. Err: %v\n", err)
}
}

// New creates a new microphone using portaudio
Expand Down Expand Up @@ -99,8 +105,6 @@ func (m *Microphone) Stream(w io.Writer) error {
klog.V(7).Infof("io.Writer succeeded. Bytes written: %d\n", byteCount)
}
}

return nil
}

// Mute silences the mic
Expand Down
2 changes: 0 additions & 2 deletions pkg/audio/replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ func (c *Client) Stream(w io.Writer) error {
klog.V(7).Infof("io.Writer succeeded. Bytes written: %d\n", byteCount)
}
}

return nil
}

// Mute silences the replay device
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/live/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ func (c *Client) listen() {
}

if c.callback != nil {
c.router.Message(byMsg)
err := c.router.Message(byMsg)
if err != nil {
klog.V(1).Infof("WebSocketClient::listen: router.Message failed. Err: %v\n", err)
}
} else {
klog.V(7).Infof("WebSocketClient::listen: msg recv (type %d): %s\n", msgType, string(byMsg))
}
Expand Down Expand Up @@ -415,9 +418,7 @@ func (c *Client) closeWs() {
func (c *Client) ping() {
klog.V(6).Infof("live.ping() ENTER\n")

var counter uint64
counter = 0

counter := 0
ticker := time.NewTicker(pingPeriod)
defer ticker.Stop()
for {
Expand Down
10 changes: 8 additions & 2 deletions pkg/client/rest/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func (d *debugRoundTrip) debugRequest(req *http.Request) string {
// Capture headers
var wc io.WriteCloser = d.newFile("req.headers")
b, _ := httputil.DumpRequest(req, false)
wc.Write(b)
_, err := wc.Write(b)
if err != nil {
d.logf("Error writing request headers: %v", err)
}
wc.Close()

ext := d.ext(req.Header)
Expand All @@ -94,7 +97,10 @@ func (d *debugRoundTrip) debugResponse(res *http.Response, ext string) {
// Capture headers
var wc io.WriteCloser = d.newFile("res.headers")
b, _ := httputil.DumpResponse(res, false)
wc.Write(b)
_, err := wc.Write(b)
if err != nil {
d.logf("Error writing response headers: %v", err)
}
wc.Close()

// Capture body
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/rest/debug/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type FileProvider struct {
files []*os.File
}

func (fp FileProvider) NewFile(p string) io.WriteCloser {
func (fp *FileProvider) NewFile(p string) io.WriteCloser {
f, err := os.Create(path.Join(fp.Path, p))
if err != nil {
panic(err)
Expand All @@ -34,7 +34,7 @@ func (fp FileProvider) NewFile(p string) io.WriteCloser {
return NewFileWriterCloser(f, p)
}

func (fp FileProvider) Flush() {
func (fp *FileProvider) Flush() {
fp.mu.Lock()
defer fp.mu.Unlock()
for _, f := range fp.files {
Expand Down
16 changes: 13 additions & 3 deletions pkg/common/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package common

import (
"flag"
"fmt"
"strconv"

klog "k8s.io/klog/v2"
Expand Down Expand Up @@ -57,10 +58,19 @@ func Init(init InitLib) {
}

klog.InitFlags(nil)
flag.Set("v", strconv.FormatInt(int64(init.LogLevel), 10))
err := flag.Set("v", strconv.FormatInt(int64(init.LogLevel), 10))
if err != nil {
fmt.Printf("Error setting log level: %v", err)
}
if init.DebugFilePath != "" {
flag.Set("logtostderr", "false")
flag.Set("log_file", init.DebugFilePath)
err = flag.Set("logtostderr", "false")
if err != nil {
fmt.Printf("Error setting logtostderr: %v", err)
}
err = flag.Set("log_file", init.DebugFilePath)
if err != nil {
fmt.Printf("Error setting log_file: %v", err)
}
}
flag.Parse()
}
3 changes: 1 addition & 2 deletions tests/prerecorded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestPrerecordedFromURL(t *testing.T) {

const preRecordedEndPoint = "https://api.deepgram.com/v1/listen"
const betaEndPoint = "https://beta.api.deepgram.com/v1/listen"
const betaHost = "beta.api.deepgram.com"

// Specify query params that are acceptable. A nil means no check
var acceptParams = map[string][]string{
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestPrerecordedFromURL(t *testing.T) {
}

// Based on query parameters, send Mock responses
var resp = &http.Response{}
var resp *http.Response
if options.Get("summarize") == "v2" {
resp = httpmock.NewStringResponse(200, MockSummarizeV2Response)
} else if options.Get("summarize") == "true" {
Expand Down