Skip to content

Commit

Permalink
Add golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jul 25, 2019
1 parent 9228e88 commit f3ce336
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 274 deletions.
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
run:
concurrency: 8
deadline: 5m
tests: false
linters:
enable-all: true
disable:
- gochecknoglobals
- goconst
- gosec
- maligned
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ env:
- GO111MODULE=on

go_import_path: github.com/go-redis/redis

before_install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all: testdeps
go vet
go get github.com/gordonklaus/ineffassign
ineffassign .
golangci-lint run

testdeps: testdata/redis/src/redis-server

Expand Down
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func BenchmarkRingWithContext(b *testing.B) {
func newClusterScenario() *clusterScenario {
return &clusterScenario{
ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"},
nodeIds: make([]string, 6),
nodeIDs: make([]string, 6),
processes: make(map[string]*redisProcess, 6),
clients: make(map[string]*redis.Client, 6),
}
Expand Down
5 changes: 3 additions & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func (c *clusterNodes) NextGeneration() uint32 {

// GC removes unused nodes.
func (c *clusterNodes) GC(generation uint32) {
//nolint:prealloc
var collected []*clusterNode
c.mu.Lock()
for addr, node := range c.allNodes {
Expand Down Expand Up @@ -651,8 +652,8 @@ type clusterClient struct {

opt *ClusterOptions
nodes *clusterNodes
state *clusterStateHolder
cmdsInfoCache *cmdsInfoCache
state *clusterStateHolder //nolint:structcheck
cmdsInfoCache *cmdsInfoCache //nolint:structcheck
}

// ClusterClient is a Redis Cluster client representing a pool of zero
Expand Down
38 changes: 19 additions & 19 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type clusterScenario struct {
ports []string
nodeIds []string
nodeIDs []string
processes map[string]*redisProcess
clients map[string]*redis.Client
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func startCluster(scenario *clusterScenario) error {

scenario.processes[port] = process
scenario.clients[port] = client
scenario.nodeIds[pos] = info[:40]
scenario.nodeIDs[pos] = info[:40]
}

// Meet cluster nodes.
Expand All @@ -120,12 +120,12 @@ func startCluster(scenario *clusterScenario) error {

// Bootstrap slaves.
for idx, slave := range scenario.slaves() {
masterId := scenario.nodeIds[idx]
masterID := scenario.nodeIDs[idx]

// Wait until master is available
err := eventually(func() error {
s := slave.ClusterNodes().Val()
wanted := masterId
wanted := masterID
if !strings.Contains(s, wanted) {
return fmt.Errorf("%q does not contain %q", s, wanted)
}
Expand All @@ -135,7 +135,7 @@ func startCluster(scenario *clusterScenario) error {
return err
}

err = slave.ClusterReplicate(masterId).Err()
err = slave.ClusterReplicate(masterID).Err()
if err != nil {
return err
}
Expand All @@ -146,30 +146,30 @@ func startCluster(scenario *clusterScenario) error {
Start: 0,
End: 4999,
Nodes: []redis.ClusterNode{{
Id: "",
ID: "",
Addr: "127.0.0.1:8220",
}, {
Id: "",
ID: "",
Addr: "127.0.0.1:8223",
}},
}, {
Start: 5000,
End: 9999,
Nodes: []redis.ClusterNode{{
Id: "",
ID: "",
Addr: "127.0.0.1:8221",
}, {
Id: "",
ID: "",
Addr: "127.0.0.1:8224",
}},
}, {
Start: 10000,
End: 16383,
Nodes: []redis.ClusterNode{{
Id: "",
ID: "",
Addr: "127.0.0.1:8222",
}, {
Id: "",
ID: "",
Addr: "127.0.0.1:8225",
}},
}}
Expand Down Expand Up @@ -592,30 +592,30 @@ var _ = Describe("ClusterClient", func() {
Start: 0,
End: 4999,
Nodes: []redis.ClusterNode{{
Id: "",
ID: "",
Addr: "127.0.0.1:8220",
}, {
Id: "",
ID: "",
Addr: "127.0.0.1:8223",
}},
}, {
Start: 5000,
End: 9999,
Nodes: []redis.ClusterNode{{
Id: "",
ID: "",
Addr: "127.0.0.1:8221",
}, {
Id: "",
ID: "",
Addr: "127.0.0.1:8224",
}},
}, {
Start: 10000,
End: 16383,
Nodes: []redis.ClusterNode{{
Id: "",
ID: "",
Addr: "127.0.0.1:8222",
}, {
Id: "",
ID: "",
Addr: "127.0.0.1:8225",
}},
}}
Expand Down Expand Up @@ -647,7 +647,7 @@ var _ = Describe("ClusterClient", func() {
})

It("should CLUSTER COUNT-FAILURE-REPORTS", func() {
n, err := client.ClusterCountFailureReports(cluster.nodeIds[0]).Result()
n, err := client.ClusterCountFailureReports(cluster.nodeIDs[0]).Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(0)))
})
Expand All @@ -665,7 +665,7 @@ var _ = Describe("ClusterClient", func() {
})

It("should CLUSTER SLAVES", func() {
nodesList, err := client.ClusterSlaves(cluster.nodeIds[0]).Result()
nodesList, err := client.ClusterSlaves(cluster.nodeIDs[0]).Result()
Expect(err).NotTo(HaveOccurred())
Expect(nodesList).Should(ContainElement(ContainSubstring("slave")))
Expect(nodesList).Should(HaveLen(1))
Expand Down
9 changes: 6 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func writeCmd(wr *proto.Writer, cmds ...Cmder) error {
}

func cmdString(cmd Cmder, val interface{}) string {
var ss []string
ss := make([]string, 0, len(cmd.Args()))
for _, arg := range cmd.Args() {
ss = append(ss, fmt.Sprint(arg))
}
Expand Down Expand Up @@ -996,6 +996,7 @@ func (cmd *XMessageSliceCmd) readReply(rd *proto.Reader) error {
func xMessageSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
msgs := make([]XMessage, n)
for i := 0; i < len(msgs); i++ {
i := i
_, err := rd.ReadArrayReply(func(rd *proto.Reader, n int64) (interface{}, error) {
id, err := rd.ReadString()
if err != nil {
Expand Down Expand Up @@ -1076,6 +1077,7 @@ func (cmd *XStreamSliceCmd) readReply(rd *proto.Reader) error {
_, cmd.err = rd.ReadArrayReply(func(rd *proto.Reader, n int64) (interface{}, error) {
cmd.val = make([]XStream, n)
for i := 0; i < len(cmd.val); i++ {
i := i
_, err := rd.ReadArrayReply(func(rd *proto.Reader, n int64) (interface{}, error) {
if n != 2 {
return nil, fmt.Errorf("got %d, wanted 2", n)
Expand Down Expand Up @@ -1441,7 +1443,7 @@ func (cmd *ScanCmd) Iterator() *ScanIterator {
//------------------------------------------------------------------------------

type ClusterNode struct {
Id string
ID string
Addr string
}

Expand Down Expand Up @@ -1528,7 +1530,7 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {
if err != nil {
return nil, err
}
nodes[j].Id = id
nodes[j].ID = id
}
}

Expand Down Expand Up @@ -1737,6 +1739,7 @@ func (cmd *GeoPosCmd) readReply(rd *proto.Reader) error {
_, cmd.err = rd.ReadArrayReply(func(rd *proto.Reader, n int64) (interface{}, error) {
cmd.val = make([]*GeoPos, n)
for i := 0; i < len(cmd.val); i++ {
i := i
_, err := rd.ReadReply(func(rd *proto.Reader, n int64) (interface{}, error) {
longitude, err := rd.ReadFloatReply()
if err != nil {
Expand Down
Loading

0 comments on commit f3ce336

Please sign in to comment.