Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: alanprot <[email protected]>
  • Loading branch information
alanprot committed Nov 29, 2024
1 parent ccf2c5f commit dd49691
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 95 deletions.
11 changes: 5 additions & 6 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package fs

import (
"io"
"io/ioutil"
"os"
"syscall"
)

// Interface is the filesystem interface type.
type Interface interface {
ReadDir(string) ([]os.FileInfo, error)
ReadDir(string) ([]os.DirEntry, error)
ReadDirNames(string) ([]string, error)
ReadDirCount(string) (int, error)
ReadFile(string) ([]byte, error)
Expand All @@ -23,8 +22,8 @@ type realFS struct{}
// FS is the way you should access the filesystem.
var fs Interface = realFS{}

func (realFS) ReadDir(path string) ([]os.FileInfo, error) {
return ioutil.ReadDir(path)
func (realFS) ReadDir(path string) ([]os.DirEntry, error) {
return os.ReadDir(path)
}

func (realFS) ReadDirNames(path string) ([]string, error) {
Expand All @@ -37,7 +36,7 @@ func (realFS) ReadDirNames(path string) ([]string, error) {
}

func (realFS) ReadFile(path string) ([]byte, error) {
return ioutil.ReadFile(path)
return os.ReadFile(path)
}

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

// ReadDir see ioutil.ReadDir
func ReadDir(path string) ([]os.FileInfo, error) {
func ReadDir(path string) ([]os.DirEntry, error) {
return fs.ReadDir(path)
}

Expand Down
37 changes: 31 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module github.com/weaveworks/common

go 1.14
go 1.21

require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/aws/aws-sdk-go v1.27.0
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
github.com/davecgh/go-spew v1.1.1
github.com/felixge/httpsnoop v1.0.3
github.com/go-kit/log v0.2.1
Expand All @@ -14,8 +13,6 @@ require (
github.com/gogo/status v1.0.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.7.3
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9
Expand All @@ -26,14 +23,42 @@ require (
github.com/prometheus/exporter-toolkit v0.8.2
github.com/sercand/kuberesolver/v4 v4.0.0
github.com/sirupsen/logrus v1.6.0
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/soheilhy/cmux v0.1.5
github.com/stretchr/testify v1.8.1
github.com/uber/jaeger-client-go v2.28.0+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible
github.com/weaveworks/promrus v1.2.0
go.uber.org/atomic v1.5.1 // indirect
golang.org/x/net v0.5.0
golang.org/x/tools v0.3.0
google.golang.org/grpc v1.53.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
go.uber.org/atomic v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
Expand All @@ -406,7 +405,6 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -636,7 +634,6 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand Down Expand Up @@ -806,7 +803,6 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
Expand Down
12 changes: 7 additions & 5 deletions httpgrpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package server
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -102,9 +102,9 @@ func ParseURL(unparsed string) (string, error) {
return "", err
}
parts := strings.SplitN(host, ".", 3)
service, namespace, domain := parts[0], "default", ""
service, _, domain := parts[0], "default", ""
if len(parts) > 1 {
namespace = parts[1]
namespace := parts[1]
domain = "." + namespace
}
if len(parts) > 2 {
Expand Down Expand Up @@ -150,7 +150,7 @@ func NewClient(address string) (*Client, error) {

// HTTPRequest wraps an ordinary HTTPRequest with a gRPC one
func HTTPRequest(r *http.Request) (*httpgrpc.HTTPRequest, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}
Expand All @@ -174,7 +174,9 @@ func WriteResponse(w http.ResponseWriter, resp *httpgrpc.HTTPResponse) error {
func WriteError(w http.ResponseWriter, err error) {
resp, ok := httpgrpc.HTTPResponseFromError(err)
if ok {
WriteResponse(w, resp)
if err := WriteResponse(w, resp); err != nil {
logging.Global().Errorf("Failed to write response: %v", err)
}
} else {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Expand Down
4 changes: 2 additions & 2 deletions httpgrpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http/httptest"
"testing"

opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
jaegercfg "github.com/uber/jaeger-client-go/config"
Expand Down Expand Up @@ -39,7 +39,7 @@ func newTestServer(handler http.Handler) (*testServer, error) {
}

httpgrpc.RegisterHTTPServer(server.grpcServer, server.Server)
go server.grpcServer.Serve(lis)
go server.grpcServer.Serve(lis) //nolint:errcheck

return server, nil
}
Expand Down
9 changes: 5 additions & 4 deletions instrument/instrument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package instrument_test
import (
"context"
"errors"
"github.com/stretchr/testify/require"
"testing"
"time"

Expand Down Expand Up @@ -47,10 +48,10 @@ func (c *spyCollector) After(ctx context.Context, method, statusCode string, sta
func TestCollectedRequest(t *testing.T) {
c := &spyCollector{}
fcalled := false
instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
require.NoError(t, instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
fcalled = true
return nil
})
}))
assert.True(t, fcalled)
assert.True(t, c.before)
assert.True(t, c.after)
Expand All @@ -59,9 +60,9 @@ func TestCollectedRequest(t *testing.T) {

func TestCollectedRequest_Error(t *testing.T) {
c := &spyCollector{}
instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
require.NoError(t, instrument.CollectedRequest(context.Background(), "test", c, nil, func(_ context.Context) error {
return errors.New("boom")
})
}))
assert.True(t, c.before)
assert.True(t, c.after)
assert.Equal(t, "500", c.afterCode)
Expand Down
2 changes: 1 addition & 1 deletion logging/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Format struct {

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

Expand Down
16 changes: 8 additions & 8 deletions logging/gokit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,31 @@ func (s *sprint) String() string {
}

func (g gokit) Debugf(format string, args ...interface{}) {
level.Debug(g.Logger).Log("msg", &sprintf{format: format, args: args})
level.Debug(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
}
func (g gokit) Debugln(args ...interface{}) {
level.Debug(g.Logger).Log("msg", &sprint{args: args})
level.Debug(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
}

func (g gokit) Infof(format string, args ...interface{}) {
level.Info(g.Logger).Log("msg", &sprintf{format: format, args: args})
level.Info(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
}
func (g gokit) Infoln(args ...interface{}) {
level.Info(g.Logger).Log("msg", &sprint{args: args})
level.Info(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
}

func (g gokit) Warnf(format string, args ...interface{}) {
level.Warn(g.Logger).Log("msg", &sprintf{format: format, args: args})
level.Warn(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
}
func (g gokit) Warnln(args ...interface{}) {
level.Warn(g.Logger).Log("msg", &sprint{args: args})
level.Warn(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
}

func (g gokit) Errorf(format string, args ...interface{}) {
level.Error(g.Logger).Log("msg", &sprintf{format: format, args: args})
level.Error(g.Logger).Log("msg", &sprintf{format: format, args: args}) //nolint:errcheck
}
func (g gokit) Errorln(args ...interface{}) {
level.Error(g.Logger).Log("msg", &sprint{args: args})
level.Error(g.Logger).Log("msg", &sprint{args: args}) //nolint:errcheck
}

func (g gokit) WithField(key string, value interface{}) Interface {
Expand Down
2 changes: 1 addition & 1 deletion logging/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Level struct {

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

Expand Down
8 changes: 5 additions & 3 deletions mflag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (s *stringValue) Set(val string) error {

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

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

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

// Parsed returns true if the command-line flags have been parsed.
Expand Down
28 changes: 14 additions & 14 deletions mflag/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
)

// ResetForTesting clears all flag state and sets the usage function as directed.
Expand Down Expand Up @@ -76,14 +78,14 @@ func TestEverything(t *testing.T) {
}
}
// Now set all flags
Set("test_bool", "true")
Set("test_int", "1")
Set("test_int64", "1")
Set("test_uint", "1")
Set("test_uint64", "1")
Set("test_string", "1")
Set("test_float64", "1")
Set("test_duration", "1s")
require.NoError(t, Set("test_bool", "true"))
require.NoError(t, Set("test_int", "1"))
require.NoError(t, Set("test_int64", "1"))
require.NoError(t, Set("test_uint", "1"))
require.NoError(t, Set("test_uint64", "1"))
require.NoError(t, Set("test_string", "1"))
require.NoError(t, Set("test_float64", "1"))
require.NoError(t, Set("testrequire.NoError(_duration", "1s"))
desired = "1"
Visit(visitor)
if len(m) != 8 {
Expand All @@ -95,9 +97,7 @@ func TestEverything(t *testing.T) {
// Now test they're visited in sort order.
var flagNames []string
Visit(func(f *Flag) {
for _, name := range f.Names {
flagNames = append(flagNames, name)
}
flagNames = append(flagNames, f.Names...)
})
if !sort.StringsAreSorted(flagNames) {
t.Errorf("flag names not sorted: %v", flagNames)
Expand Down Expand Up @@ -276,7 +276,7 @@ func testPanic(f *FlagSet, t *testing.T) {
args := []string{
"-int", "21",
}
f.Parse(args)
require.NoError(t, f.Parse(args))
}

func TestParsePanic(t *testing.T) {
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestSetOutput(t *testing.T) {
var buf bytes.Buffer
flags.SetOutput(&buf)
flags.Init("test", ContinueOnError)
flags.Parse([]string{"-unknown"})
require.NoError(t, flags.Parse([]string{"-unknown"}))
if out := buf.String(); !strings.Contains(out, "-unknown") {
t.Logf("expected output mentioning unknown; got %q", out)
}
Expand Down Expand Up @@ -520,7 +520,7 @@ func TestMergeFlags(t *testing.T) {
base.String([]string{"f"}, "", "")

fs := NewFlagSet("test", ContinueOnError)
Merge(fs, base)
require.NoError(t, Merge(fs, base))
if len(fs.formal) != 1 {
t.Fatalf("FlagCount (%d) != number (1) of elements merged", len(fs.formal))
}
Expand Down
Loading

0 comments on commit dd49691

Please sign in to comment.