Skip to content

Commit 6c93b83

Browse files
committed
cmd: address staticcheck linter warnings
These ones: internal/storage/statsd/client/client.go:50:12: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) _, err := fmt.Fprintf(c.conn, formatted) ^ internal/storage/bigquery/client/client.go:74:38: SA1019: oauth2.NoContext is deprecated: Use context.Background() or context.TODO() instead. (staticcheck) token, err := jwtConfig.TokenSource(oauth2.NoContext).Token() ^ internal/storage/bigquery/client/client.go:91:26: SA1019: oauth2.NoContext is deprecated: Use context.Background() or context.TODO() instead. (staticcheck) client := config.Client(oauth2.NoContext, token) ^ internal/storage/bigquery/client/client.go:93:18: SA1019: bigquery.New is deprecated: please use NewService instead. To provide a custom HTTP client, use option.WithHTTPClient. If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. (staticcheck) service, err := bigquery.New(client) ^ internal/api/handler.go:138:15: SA1019: http.CloseNotifier has been deprecated since Go 1.11 and an alternative has been available since Go 1.7: the CloseNotifier interface predates Go's context package. New code should use Request.Context instead. (staticcheck) cn, ok := w.(http.CloseNotifier) ^ NOTE I am not very sure if I'm doing the right thing fixing the last warning. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 071a995 commit 6c93b83

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

cmd/internal/api/handler.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ func writeResult(res interface{}, w http.ResponseWriter) error {
135135
}
136136

137137
func streamResults(eventChannel *events.EventChannel, w http.ResponseWriter, r *http.Request, m manager.Manager) error {
138-
cn, ok := w.(http.CloseNotifier)
139-
if !ok {
140-
return errors.New("could not access http.CloseNotifier")
141-
}
142138
flusher, ok := w.(http.Flusher)
143139
if !ok {
144140
return errors.New("could not access http.Flusher")
@@ -151,7 +147,7 @@ func streamResults(eventChannel *events.EventChannel, w http.ResponseWriter, r *
151147
enc := json.NewEncoder(w)
152148
for {
153149
select {
154-
case <-cn.CloseNotify():
150+
case <-r.Context().Done():
155151
m.CloseEventChannel(eventChannel.GetWatchId())
156152
return nil
157153
case ev := <-eventChannel.GetChannel():

cmd/internal/storage/bigquery/client/client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package client
1616

1717
import (
18+
"context"
1819
"flag"
1920
"fmt"
2021
"io/ioutil"
@@ -23,6 +24,7 @@ import (
2324
"golang.org/x/oauth2"
2425
"golang.org/x/oauth2/jwt"
2526
bigquery "google.golang.org/api/bigquery/v2"
27+
"google.golang.org/api/option"
2628
)
2729

2830
var (
@@ -71,7 +73,7 @@ func connect() (*oauth2.Token, *bigquery.Service, error) {
7173
PrivateKey: pemBytes,
7274
TokenURL: "https://accounts.google.com/o/oauth2/token",
7375
}
74-
token, err := jwtConfig.TokenSource(oauth2.NoContext).Token()
76+
token, err := jwtConfig.TokenSource(context.Background()).Token()
7577
if err != nil {
7678
return nil, nil, err
7779
}
@@ -88,9 +90,9 @@ func connect() (*oauth2.Token, *bigquery.Service, error) {
8890
TokenURL: "https://accounts.google.com/o/oauth2/token",
8991
},
9092
}
91-
client := config.Client(oauth2.NoContext, token)
93+
client := config.Client(context.Background(), token)
9294

93-
service, err := bigquery.New(client)
95+
service, err := bigquery.NewService(context.Background(), option.WithHTTPClient(client))
9496
if err != nil {
9597
fmt.Printf("Failed to create new service: %v\n", err)
9698
return nil, nil, err

cmd/internal/storage/statsd/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *Client) Close() error {
4747
func (c *Client) Send(namespace, containerName, key string, value uint64) error {
4848
// only send counter value
4949
formatted := fmt.Sprintf("%s.%s.%s:%d|g", namespace, containerName, key, value)
50-
_, err := fmt.Fprintf(c.conn, formatted)
50+
_, err := fmt.Fprint(c.conn, formatted)
5151
if err != nil {
5252
return fmt.Errorf("failed to send data %q: %v", formatted, err)
5353
}

0 commit comments

Comments
 (0)