Skip to content

Commit 2f10bdf

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
fix: resolve golangci-lint errcheck and staticcheck findings
- Use tagged switch in microphone_record.go (QF1002) - Check rows.Close() return values in acl/store.go (errcheck) - Check fmt.Fprintf/Fprintln return values in jniserviceadmin (errcheck)
1 parent d12e9d4 commit 2f10bdf

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

cmd/jnicli/microphone_record.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ The resulting M4A is written to stdout or a file.`,
4949
return err
5050
}
5151

52-
switch {
53-
case output == "-" || output == "":
52+
switch output {
53+
case "-", "":
5454
_, err := os.Stdout.Write(data)
5555
return err
5656
default:

cmd/jniserviceadmin/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ var clientsListCmd = &cobra.Command{
5858
}
5959

6060
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
61-
fmt.Fprintln(w, "CLIENT_ID\tFINGERPRINT\tREGISTERED_AT")
61+
_, _ = fmt.Fprintln(w, "CLIENT_ID\tFINGERPRINT\tREGISTERED_AT")
6262
for _, c := range clients {
63-
fmt.Fprintf(w, "%s\t%s\t%s\n", c.ClientID, c.Fingerprint, c.RegisteredAt.Format("2006-01-02T15:04:05Z"))
63+
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\n", c.ClientID, c.Fingerprint, c.RegisteredAt.Format("2006-01-02T15:04:05Z"))
6464
}
6565
return w.Flush()
6666
},
@@ -75,7 +75,7 @@ var clientsRevokeCmd = &cobra.Command{
7575
if err := store.RevokeClient(clientID); err != nil {
7676
return err
7777
}
78-
fmt.Fprintf(os.Stdout, "Revoked client %q and all associated grants.\n", clientID)
78+
_, _ = fmt.Fprintf(os.Stdout, "Revoked client %q and all associated grants.\n", clientID)
7979
return nil
8080
},
8181
}
@@ -101,9 +101,9 @@ var grantsListCmd = &cobra.Command{
101101
}
102102

103103
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
104-
fmt.Fprintln(w, "CLIENT_ID\tMETHOD_PATTERN\tGRANTED_AT\tGRANTED_BY")
104+
_, _ = fmt.Fprintln(w, "CLIENT_ID\tMETHOD_PATTERN\tGRANTED_AT\tGRANTED_BY")
105105
for _, g := range grants {
106-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", g.ClientID, g.MethodPattern, g.GrantedAt.Format("2006-01-02T15:04:05Z"), g.GrantedBy)
106+
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", g.ClientID, g.MethodPattern, g.GrantedAt.Format("2006-01-02T15:04:05Z"), g.GrantedBy)
107107
}
108108
return w.Flush()
109109
},
@@ -119,7 +119,7 @@ var grantsApproveCmd = &cobra.Command{
119119
if err := store.Grant(clientID, pattern, "cli:admin"); err != nil {
120120
return err
121121
}
122-
fmt.Fprintf(os.Stdout, "Granted %q to client %q.\n", pattern, clientID)
122+
_, _ = fmt.Fprintf(os.Stdout, "Granted %q to client %q.\n", pattern, clientID)
123123
return nil
124124
},
125125
}
@@ -134,7 +134,7 @@ var grantsRevokeCmd = &cobra.Command{
134134
if err := store.Revoke(clientID, pattern); err != nil {
135135
return err
136136
}
137-
fmt.Fprintf(os.Stdout, "Revoked %q from client %q.\n", pattern, clientID)
137+
_, _ = fmt.Fprintf(os.Stdout, "Revoked %q from client %q.\n", pattern, clientID)
138138
return nil
139139
},
140140
}
@@ -156,9 +156,9 @@ var requestsListCmd = &cobra.Command{
156156
}
157157

158158
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
159-
fmt.Fprintln(w, "ID\tCLIENT_ID\tMETHODS\tREQUESTED_AT")
159+
_, _ = fmt.Fprintln(w, "ID\tCLIENT_ID\tMETHODS\tREQUESTED_AT")
160160
for _, r := range requests {
161-
fmt.Fprintf(w, "%d\t%s\t%s\t%s\n", r.ID, r.ClientID, strings.Join(r.Methods, ","), r.RequestedAt.Format("2006-01-02T15:04:05Z"))
161+
_, _ = fmt.Fprintf(w, "%d\t%s\t%s\t%s\n", r.ID, r.ClientID, strings.Join(r.Methods, ","), r.RequestedAt.Format("2006-01-02T15:04:05Z"))
162162
}
163163
return w.Flush()
164164
},
@@ -176,7 +176,7 @@ var requestsApproveCmd = &cobra.Command{
176176
if err := store.ApproveRequest(id, "cli:admin"); err != nil {
177177
return err
178178
}
179-
fmt.Fprintf(os.Stdout, "Approved request %d.\n", id)
179+
_, _ = fmt.Fprintf(os.Stdout, "Approved request %d.\n", id)
180180
return nil
181181
},
182182
}
@@ -193,7 +193,7 @@ var requestsDenyCmd = &cobra.Command{
193193
if err := store.DenyRequest(id); err != nil {
194194
return err
195195
}
196-
fmt.Fprintf(os.Stdout, "Denied request %d.\n", id)
196+
_, _ = fmt.Fprintf(os.Stdout, "Denied request %d.\n", id)
197197
return nil
198198
},
199199
}

grpc/server/acl/store.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (s *Store) ListClients() ([]ClientInfo, error) {
119119
if err != nil {
120120
return nil, fmt.Errorf("querying clients: %w", err)
121121
}
122-
defer rows.Close()
122+
defer func() { _ = rows.Close() }()
123123

124124
var clients []ClientInfo
125125
for rows.Next() {
@@ -210,7 +210,7 @@ func (s *Store) ListGrants(clientID string) ([]GrantInfo, error) {
210210
if err != nil {
211211
return nil, fmt.Errorf("querying grants: %w", err)
212212
}
213-
defer rows.Close()
213+
defer func() { _ = rows.Close() }()
214214

215215
var grants []GrantInfo
216216
for rows.Next() {
@@ -246,7 +246,7 @@ func (s *Store) IsMethodAllowed(
246246
if err != nil {
247247
return false, fmt.Errorf("querying grants for %q: %w", clientID, err)
248248
}
249-
defer rows.Close()
249+
defer func() { _ = rows.Close() }()
250250

251251
for rows.Next() {
252252
var pattern string
@@ -313,7 +313,7 @@ func (s *Store) ListPendingRequests() ([]RequestInfo, error) {
313313
if err != nil {
314314
return nil, fmt.Errorf("querying pending requests: %w", err)
315315
}
316-
defer rows.Close()
316+
defer func() { _ = rows.Close() }()
317317

318318
var requests []RequestInfo
319319
for rows.Next() {

0 commit comments

Comments
 (0)