Skip to content

Commit dd49691

Browse files
committed
fix lint
Signed-off-by: alanprot <alanprot@gmail.com>
1 parent ccf2c5f commit dd49691

File tree

21 files changed

+148
-95
lines changed

21 files changed

+148
-95
lines changed

fs/fs.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ package fs
22

33
import (
44
"io"
5-
"io/ioutil"
65
"os"
76
"syscall"
87
)
98

109
// Interface is the filesystem interface type.
1110
type Interface interface {
12-
ReadDir(string) ([]os.FileInfo, error)
11+
ReadDir(string) ([]os.DirEntry, error)
1312
ReadDirNames(string) ([]string, error)
1413
ReadDirCount(string) (int, error)
1514
ReadFile(string) ([]byte, error)
@@ -23,8 +22,8 @@ type realFS struct{}
2322
// FS is the way you should access the filesystem.
2423
var fs Interface = realFS{}
2524

26-
func (realFS) ReadDir(path string) ([]os.FileInfo, error) {
27-
return ioutil.ReadDir(path)
25+
func (realFS) ReadDir(path string) ([]os.DirEntry, error) {
26+
return os.ReadDir(path)
2827
}
2928

3029
func (realFS) ReadDirNames(path string) ([]string, error) {
@@ -37,7 +36,7 @@ func (realFS) ReadDirNames(path string) ([]string, error) {
3736
}
3837

3938
func (realFS) ReadFile(path string) ([]byte, error) {
40-
return ioutil.ReadFile(path)
39+
return os.ReadFile(path)
4140
}
4241

4342
func (realFS) Lstat(path string, stat *syscall.Stat_t) error {
@@ -55,7 +54,7 @@ func (realFS) Open(path string) (io.ReadWriteCloser, error) {
5554
// trampolines here to allow users to do fs.ReadDir etc
5655

5756
// ReadDir see ioutil.ReadDir
58-
func ReadDir(path string) ([]os.FileInfo, error) {
57+
func ReadDir(path string) ([]os.DirEntry, error) {
5958
return fs.ReadDir(path)
6059
}
6160

go.mod

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module github.com/weaveworks/common
22

3-
go 1.14
3+
go 1.21
44

55
require (
66
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
77
github.com/aws/aws-sdk-go v1.27.0
8-
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
98
github.com/davecgh/go-spew v1.1.1
109
github.com/felixge/httpsnoop v1.0.3
1110
github.com/go-kit/log v0.2.1
@@ -14,8 +13,6 @@ require (
1413
github.com/gogo/status v1.0.3
1514
github.com/golang/protobuf v1.5.2
1615
github.com/gorilla/mux v1.7.3
17-
github.com/mattn/go-colorable v0.0.9 // indirect
18-
github.com/mattn/go-isatty v0.0.4 // indirect
1916
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
2017
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02
2118
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9
@@ -26,14 +23,42 @@ require (
2623
github.com/prometheus/exporter-toolkit v0.8.2
2724
github.com/sercand/kuberesolver/v4 v4.0.0
2825
github.com/sirupsen/logrus v1.6.0
29-
github.com/soheilhy/cmux v0.1.5 // indirect
26+
github.com/soheilhy/cmux v0.1.5
3027
github.com/stretchr/testify v1.8.1
3128
github.com/uber/jaeger-client-go v2.28.0+incompatible
3229
github.com/uber/jaeger-lib v2.2.0+incompatible
3330
github.com/weaveworks/promrus v1.2.0
34-
go.uber.org/atomic v1.5.1 // indirect
3531
golang.org/x/net v0.5.0
3632
golang.org/x/tools v0.3.0
3733
google.golang.org/grpc v1.53.0
3834
gopkg.in/yaml.v2 v2.4.0
3935
)
36+
37+
require (
38+
github.com/beorn7/perks v1.0.1 // indirect
39+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
40+
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
41+
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
42+
github.com/fsnotify/fsnotify v1.5.4 // indirect
43+
github.com/go-logfmt/logfmt v0.5.1 // indirect
44+
github.com/jpillora/backoff v1.0.0 // indirect
45+
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
46+
github.com/mattn/go-colorable v0.0.9 // indirect
47+
github.com/mattn/go-isatty v0.0.4 // indirect
48+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
49+
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
50+
github.com/prometheus/client_model v0.3.0 // indirect
51+
github.com/prometheus/common v0.37.0 // indirect
52+
github.com/prometheus/procfs v0.8.0 // indirect
53+
go.uber.org/atomic v1.5.1 // indirect
54+
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
55+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
56+
golang.org/x/oauth2 v0.4.0 // indirect
57+
golang.org/x/sync v0.1.0 // indirect
58+
golang.org/x/sys v0.5.0 // indirect
59+
golang.org/x/text v0.6.0 // indirect
60+
google.golang.org/appengine v1.6.7 // indirect
61+
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
62+
google.golang.org/protobuf v1.28.1 // indirect
63+
gopkg.in/yaml.v3 v3.0.1 // indirect
64+
)

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
393393
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
394394
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
395395
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
396-
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
397396
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
398397
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
399398
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
@@ -406,7 +405,6 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
406405
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
407406
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
408407
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
409-
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
410408
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
411409
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
412410
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -636,7 +634,6 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
636634
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
637635
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
638636
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
639-
github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
640637
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
641638
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
642639
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
@@ -806,7 +803,6 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
806803
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
807804
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
808805
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
809-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
810806
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
811807
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
812808
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=

httpgrpc/server/server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package server
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net"
88
"net/http"
99
"net/http/httptest"
@@ -102,9 +102,9 @@ func ParseURL(unparsed string) (string, error) {
102102
return "", err
103103
}
104104
parts := strings.SplitN(host, ".", 3)
105-
service, namespace, domain := parts[0], "default", ""
105+
service, _, domain := parts[0], "default", ""
106106
if len(parts) > 1 {
107-
namespace = parts[1]
107+
namespace := parts[1]
108108
domain = "." + namespace
109109
}
110110
if len(parts) > 2 {
@@ -150,7 +150,7 @@ func NewClient(address string) (*Client, error) {
150150

151151
// HTTPRequest wraps an ordinary HTTPRequest with a gRPC one
152152
func HTTPRequest(r *http.Request) (*httpgrpc.HTTPRequest, error) {
153-
body, err := ioutil.ReadAll(r.Body)
153+
body, err := io.ReadAll(r.Body)
154154
if err != nil {
155155
return nil, err
156156
}
@@ -174,7 +174,9 @@ func WriteResponse(w http.ResponseWriter, resp *httpgrpc.HTTPResponse) error {
174174
func WriteError(w http.ResponseWriter, err error) {
175175
resp, ok := httpgrpc.HTTPResponseFromError(err)
176176
if ok {
177-
WriteResponse(w, resp)
177+
if err := WriteResponse(w, resp); err != nil {
178+
logging.Global().Errorf("Failed to write response: %v", err)
179+
}
178180
} else {
179181
http.Error(w, err.Error(), http.StatusInternalServerError)
180182
}

httpgrpc/server/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"net/http/httptest"
1010
"testing"
1111

12-
opentracing "github.com/opentracing/opentracing-go"
12+
"github.com/opentracing/opentracing-go"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
1515
jaegercfg "github.com/uber/jaeger-client-go/config"
@@ -39,7 +39,7 @@ func newTestServer(handler http.Handler) (*testServer, error) {
3939
}
4040

4141
httpgrpc.RegisterHTTPServer(server.grpcServer, server.Server)
42-
go server.grpcServer.Serve(lis)
42+
go server.grpcServer.Serve(lis) //nolint:errcheck
4343

4444
return server, nil
4545
}

instrument/instrument_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package instrument_test
33
import (
44
"context"
55
"errors"
6+
"github.com/stretchr/testify/require"
67
"testing"
78
"time"
89

@@ -47,10 +48,10 @@ func (c *spyCollector) After(ctx context.Context, method, statusCode string, sta
4748
func TestCollectedRequest(t *testing.T) {
4849
c := &spyCollector{}
4950
fcalled := false
50-
instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
51+
require.NoError(t, instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
5152
fcalled = true
5253
return nil
53-
})
54+
}))
5455
assert.True(t, fcalled)
5556
assert.True(t, c.before)
5657
assert.True(t, c.after)
@@ -59,9 +60,9 @@ func TestCollectedRequest(t *testing.T) {
5960

6061
func TestCollectedRequest_Error(t *testing.T) {
6162
c := &spyCollector{}
62-
instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
63+
require.NoError(t, instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
6364
return errors.New("boom")
64-
})
65+
}))
6566
assert.True(t, c.before)
6667
assert.True(t, c.after)
6768
assert.Equal(t, "500", c.afterCode)

logging/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Format struct {
1515

1616
// RegisterFlags adds the log format flag to the provided flagset.
1717
func (f *Format) RegisterFlags(fs *flag.FlagSet) {
18-
f.Set("logfmt")
18+
f.Set("logfmt") //nolint:errcheck
1919
fs.Var(f, "log.format", "Output log messages in the given format. Valid formats: [logfmt, json]")
2020
}
2121

logging/gokit.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,31 @@ func (s *sprint) String() string {
6262
}
6363

6464
func (g gokit) Debugf(format string, args ...interface{}) {
65-
level.Debug(g.Logger).Log("msg", &sprintf{format: format, args: args})
65+
level.Debug(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
6666
}
6767
func (g gokit) Debugln(args ...interface{}) {
68-
level.Debug(g.Logger).Log("msg", &sprint{args: args})
68+
level.Debug(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
6969
}
7070

7171
func (g gokit) Infof(format string, args ...interface{}) {
72-
level.Info(g.Logger).Log("msg", &sprintf{format: format, args: args})
72+
level.Info(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
7373
}
7474
func (g gokit) Infoln(args ...interface{}) {
75-
level.Info(g.Logger).Log("msg", &sprint{args: args})
75+
level.Info(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
7676
}
7777

7878
func (g gokit) Warnf(format string, args ...interface{}) {
79-
level.Warn(g.Logger).Log("msg", &sprintf{format: format, args: args})
79+
level.Warn(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
8080
}
8181
func (g gokit) Warnln(args ...interface{}) {
82-
level.Warn(g.Logger).Log("msg", &sprint{args: args})
82+
level.Warn(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
8383
}
8484

8585
func (g gokit) Errorf(format string, args ...interface{}) {
86-
level.Error(g.Logger).Log("msg", &sprintf{format: format, args: args})
86+
level.Error(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
8787
}
8888
func (g gokit) Errorln(args ...interface{}) {
89-
level.Error(g.Logger).Log("msg", &sprint{args: args})
89+
level.Error(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
9090
}
9191

9292
func (g gokit) WithField(key string, value interface{}) Interface {

logging/level.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Level struct {
3232

3333
// RegisterFlags adds the log level flag to the provided flagset.
3434
func (l *Level) RegisterFlags(f *flag.FlagSet) {
35-
l.Set("info")
35+
l.Set("info") //nolint:errcheck
3636
f.Var(l, "log.level", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error]")
3737
}
3838

mflag/flag.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (s *stringValue) Set(val string) error {
230230

231231
func (s *stringValue) Get() interface{} { return string(*s) }
232232

233-
func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
233+
func (s *stringValue) String() string { return string(*s) }
234234

235235
// -- float64 Value
236236
type float64Value float64
@@ -1026,7 +1026,9 @@ func (fs *FlagSet) parseOne() (bool, string, error) {
10261026
return false, "", fs.failf("invalid boolean value %q for -%s: %v", value, name, err)
10271027
}
10281028
} else {
1029-
fv.Set("true")
1029+
if err := fv.Set("true"); err != nil {
1030+
return false, "", fs.failf("invalid boolean value for -%s: %v", name, err)
1031+
}
10301032
}
10311033
} else {
10321034
// It must have a value, which might be the next argument.
@@ -1162,7 +1164,7 @@ func (fs *FlagSet) Parsed() bool {
11621164
// after all flags are defined and before flags are accessed by the program.
11631165
func Parse() {
11641166
// Ignore errors; CommandLine is set for ExitOnError.
1165-
CommandLine.Parse(os.Args[1:])
1167+
CommandLine.Parse(os.Args[1:]) //nolint:errcheck
11661168
}
11671169

11681170
// Parsed returns true if the command-line flags have been parsed.

0 commit comments

Comments
 (0)