From 14c843ef89ce7d9a878f67e8910d54e5dca0acb6 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 16 Jul 2020 09:52:07 +0300 Subject: [PATCH] gofumports --- cluster_test.go | 1 - command.go | 2 +- commands.go | 10 ++-- commands_test.go | 88 +++++++++++++------------------- example/otel/example-client.go | 8 +-- example_test.go | 6 ++- internal/hashtag/hashtag_test.go | 4 -- internal/instruments.go | 1 - internal/pool/pool.go | 6 ++- internal/proto/writer.go | 2 +- iterator_test.go | 8 +-- ring.go | 6 +-- script.go | 8 +-- universal.go | 8 +-- universal_test.go | 1 - 15 files changed, 72 insertions(+), 87 deletions(-) diff --git a/cluster_test.go b/cluster_test.go index 46948a89..5c125de6 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -50,7 +50,6 @@ func (s *clusterScenario) addrs() []string { func (s *clusterScenario) newClusterClientUnsafe(opt *redis.ClusterOptions) *redis.ClusterClient { opt.Addrs = s.addrs() return redis.NewClusterClient(opt) - } func (s *clusterScenario) newClusterClient( diff --git a/command.go b/command.go index bd8808f2..622fdb44 100644 --- a/command.go +++ b/command.go @@ -1857,7 +1857,7 @@ func newGeoLocationSliceParser(q *GeoRadiusQuery) proto.MultiBulkParse { Name: vv, }) case *GeoLocation: - //TODO: avoid copying + // TODO: avoid copying locs = append(locs, *vv) default: return nil, fmt.Errorf("got %T, expected string or *GeoLocation", v) diff --git a/commands.go b/commands.go index 9bf9c0aa..0ef1b606 100644 --- a/commands.go +++ b/commands.go @@ -333,10 +333,12 @@ type StatefulCmdable interface { ClientSetName(ctx context.Context, name string) *BoolCmd } -var _ Cmdable = (*Client)(nil) -var _ Cmdable = (*Tx)(nil) -var _ Cmdable = (*Ring)(nil) -var _ Cmdable = (*ClusterClient)(nil) +var ( + _ Cmdable = (*Client)(nil) + _ Cmdable = (*Tx)(nil) + _ Cmdable = (*Ring)(nil) + _ Cmdable = (*ClusterClient)(nil) +) type cmdable func(ctx context.Context, cmd Cmder) error diff --git a/commands_test.go b/commands_test.go index b677e09c..0fcea97a 100644 --- a/commands_test.go +++ b/commands_test.go @@ -28,7 +28,6 @@ var _ = Describe("Commands", func() { }) Describe("server", func() { - It("should Auth", func() { cmds, err := client.Pipelined(ctx, func(pipe redis.Pipeliner) error { pipe.Auth(ctx, "password") @@ -267,11 +266,9 @@ var _ = Describe("Commands", func() { Expect(cmd.LastKeyPos).To(Equal(int8(0))) Expect(cmd.StepCount).To(Equal(int8(0))) }) - }) Describe("debugging", func() { - It("should DebugObject", func() { err := client.DebugObject(ctx, "foo").Err() Expect(err).To(MatchError("ERR no such key")) @@ -299,11 +296,9 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(n).NotTo(BeZero()) }) - }) Describe("keys", func() { - It("should Del", func() { err := client.Set(ctx, "key1", "Hello", 0).Err() Expect(err).NotTo(HaveOccurred()) @@ -760,11 +755,9 @@ var _ = Describe("Commands", func() { Expect(type_.Err()).NotTo(HaveOccurred()) Expect(type_.Val()).To(Equal("string")) }) - }) Describe("scanning", func() { - It("should Scan", func() { for i := 0; i < 1000; i++ { set := client.Set(ctx, fmt.Sprintf("key%d", i), "hello", 0) @@ -815,11 +808,9 @@ var _ = Describe("Commands", func() { Expect(keys).NotTo(BeEmpty()) Expect(cursor).NotTo(BeZero()) }) - }) Describe("strings", func() { - It("should Append", func() { n, err := client.Exists(ctx, "key").Result() Expect(err).NotTo(HaveOccurred()) @@ -1253,11 +1244,9 @@ var _ = Describe("Commands", func() { Expect(strLen.Err()).NotTo(HaveOccurred()) Expect(strLen.Val()).To(Equal(int64(0))) }) - }) Describe("hashes", func() { - It("should HDel", func() { hSet := client.HSet(ctx, "hash", "key", "hello") Expect(hSet.Err()).NotTo(HaveOccurred()) @@ -1438,7 +1427,6 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(slice).To(Equal([]string{"hello1", "hello2"})) }) - }) Describe("hyperloglog", func() { @@ -1467,7 +1455,6 @@ var _ = Describe("Commands", func() { }) Describe("lists", func() { - It("should BLPop", func() { rPush := client.RPush(ctx, "list1", "a", "b", "c") Expect(rPush.Err()).NotTo(HaveOccurred()) @@ -1849,11 +1836,9 @@ var _ = Describe("Commands", func() { Expect(lRange.Err()).NotTo(HaveOccurred()) Expect(lRange.Val()).To(Equal([]string{})) }) - }) Describe("sets", func() { - It("should SAdd", func() { sAdd := client.SAdd(ctx, "set", "Hello") Expect(sAdd.Err()).NotTo(HaveOccurred()) @@ -2057,7 +2042,6 @@ var _ = Describe("Commands", func() { sMembers := client.SMembers(ctx, "set") Expect(sMembers.Err()).NotTo(HaveOccurred()) Expect(sMembers.Val()).To(HaveLen(2)) - }) It("should SPopN", func() { @@ -2172,11 +2156,9 @@ var _ = Describe("Commands", func() { Expect(sMembers.Err()).NotTo(HaveOccurred()) Expect(sMembers.Val()).To(HaveLen(5)) }) - }) Describe("sorted sets", func() { - It("should BZPopMax", func() { err := client.ZAdd(ctx, "zset1", &redis.Z{ Score: 1, @@ -3400,7 +3382,6 @@ var _ = Describe("Commands", func() { Member: "two", }})) }) - }) Describe("streams", func() { @@ -3568,13 +3549,15 @@ var _ = Describe("Commands", func() { It("should XRead", func() { res, err := client.XReadStreams(ctx, "stream", "0").Result() Expect(err).NotTo(HaveOccurred()) - Expect(res).To(Equal([]redis.XStream{{ - Stream: "stream", - Messages: []redis.XMessage{ - {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, - {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, - {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, - }}, + Expect(res).To(Equal([]redis.XStream{ + { + Stream: "stream", + Messages: []redis.XMessage{ + {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, + {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, + {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, + }, + }, })) _, err = client.XReadStreams(ctx, "stream", "3").Result() @@ -3588,12 +3571,14 @@ var _ = Describe("Commands", func() { Block: 100 * time.Millisecond, }).Result() Expect(err).NotTo(HaveOccurred()) - Expect(res).To(Equal([]redis.XStream{{ - Stream: "stream", - Messages: []redis.XMessage{ - {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, - {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, - }}, + Expect(res).To(Equal([]redis.XStream{ + { + Stream: "stream", + Messages: []redis.XMessage{ + {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, + {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, + }, + }, })) _, err = client.XRead(ctx, &redis.XReadArgs{ @@ -3615,13 +3600,15 @@ var _ = Describe("Commands", func() { Streams: []string{"stream", ">"}, }).Result() Expect(err).NotTo(HaveOccurred()) - Expect(res).To(Equal([]redis.XStream{{ - Stream: "stream", - Messages: []redis.XMessage{ - {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, - {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, - {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, - }}, + Expect(res).To(Equal([]redis.XStream{ + { + Stream: "stream", + Messages: []redis.XMessage{ + {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, + {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, + {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, + }, + }, })) }) @@ -3642,13 +3629,15 @@ var _ = Describe("Commands", func() { Streams: []string{"stream", "0"}, }).Result() Expect(err).NotTo(HaveOccurred()) - Expect(res).To(Equal([]redis.XStream{{ - Stream: "stream", - Messages: []redis.XMessage{ - {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, - {ID: "2-0", Values: nil}, - {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, - }}, + Expect(res).To(Equal([]redis.XStream{ + { + Stream: "stream", + Messages: []redis.XMessage{ + {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, + {ID: "2-0", Values: nil}, + {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, + }, + }, })) }) @@ -3935,7 +3924,6 @@ var _ = Describe("Commands", func() { }) Describe("marshaling/unmarshaling", func() { - type convTest struct { value interface{} wanted string @@ -3980,11 +3968,9 @@ var _ = Describe("Commands", func() { Expect(deref(test.dest)).To(Equal(test.value)) } }) - }) Describe("json marshaling/unmarshaling", func() { - BeforeEach(func() { value := &numberStruct{Number: 42} err := client.Set(ctx, "key", value, 0).Err() @@ -4003,11 +3989,9 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(value.Number).To(Equal(42)) }) - }) Describe("Eval", func() { - It("returns keys and values", func() { vals, err := client.Eval( ctx, @@ -4028,9 +4012,7 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"})) }) - }) - }) type numberStruct struct { diff --git a/example/otel/example-client.go b/example/otel/example-client.go index 56b830bc..c9b6549d 100644 --- a/example/otel/example-client.go +++ b/example/otel/example-client.go @@ -2,6 +2,10 @@ package main import ( "context" + "log" + "sync" + "time" + "github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8/redisext" "go.opentelemetry.io/otel/api/global" @@ -9,9 +13,6 @@ import ( traceStdout "go.opentelemetry.io/otel/exporters/trace/stdout" "go.opentelemetry.io/otel/sdk/metric/controller/push" sdktrace "go.opentelemetry.io/otel/sdk/trace" - "log" - "sync" - "time" ) func main() { @@ -76,4 +77,3 @@ func main() { <-time.After(5 * time.Second) span.End() } - diff --git a/example_test.go b/example_test.go index afb2a754..c4c6469c 100644 --- a/example_test.go +++ b/example_test.go @@ -10,8 +10,10 @@ import ( "github.com/go-redis/redis/v8" ) -var ctx = context.Background() -var rdb *redis.Client +var ( + ctx = context.Background() + rdb *redis.Client +) func init() { rdb = redis.NewClient(&redis.Options{ diff --git a/internal/hashtag/hashtag_test.go b/internal/hashtag/hashtag_test.go index 87aca6ff..a8ce63fe 100644 --- a/internal/hashtag/hashtag_test.go +++ b/internal/hashtag/hashtag_test.go @@ -14,7 +14,6 @@ func TestGinkgoSuite(t *testing.T) { } var _ = Describe("CRC16", func() { - // http://redis.io/topics/cluster-spec#keys-distribution-model It("should calculate CRC16", func() { tests := []struct { @@ -29,11 +28,9 @@ var _ = Describe("CRC16", func() { Expect(crc16sum(test.s)).To(Equal(test.n), "for %s", test.s) } }) - }) var _ = Describe("HashSlot", func() { - It("should calculate hash slots", func() { tests := []struct { key string @@ -70,5 +67,4 @@ var _ = Describe("HashSlot", func() { Expect(Slot(test.one)).To(Equal(Slot(test.two)), "for %s <-> %s", test.one, test.two) } }) - }) diff --git a/internal/instruments.go b/internal/instruments.go index 5380ca2e..ff078170 100644 --- a/internal/instruments.go +++ b/internal/instruments.go @@ -29,4 +29,3 @@ func init() { metric.WithDescription("the number of connections created"), ) } - diff --git a/internal/pool/pool.go b/internal/pool/pool.go index a1422954..c84a0060 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -11,8 +11,10 @@ import ( "github.com/go-redis/redis/v8/internal" ) -var ErrClosed = errors.New("redis: client is closed") -var ErrPoolTimeout = errors.New("redis: connection pool timeout") +var ( + ErrClosed = errors.New("redis: client is closed") + ErrPoolTimeout = errors.New("redis: connection pool timeout") +) var timers = sync.Pool{ New: func() interface{} { diff --git a/internal/proto/writer.go b/internal/proto/writer.go index 2ce02dc2..81b09b8e 100644 --- a/internal/proto/writer.go +++ b/internal/proto/writer.go @@ -13,7 +13,7 @@ import ( type writer interface { io.Writer io.ByteWriter - //io.StringWriter + // io.StringWriter WriteString(s string) (n int, err error) } diff --git a/iterator_test.go b/iterator_test.go index d171d304..7a64f025 100644 --- a/iterator_test.go +++ b/iterator_test.go @@ -12,7 +12,7 @@ import ( var _ = Describe("ScanIterator", func() { var client *redis.Client - var seed = func(n int) error { + seed := func(n int) error { pipe := client.Pipeline() for i := 1; i <= n; i++ { pipe.Set(ctx, fmt.Sprintf("K%02d", i), "x", 0).Err() @@ -21,7 +21,7 @@ var _ = Describe("ScanIterator", func() { return err } - var extraSeed = func(n int, m int) error { + extraSeed := func(n int, m int) error { pipe := client.Pipeline() for i := 1; i <= m; i++ { pipe.Set(ctx, fmt.Sprintf("A%02d", i), "x", 0).Err() @@ -33,8 +33,8 @@ var _ = Describe("ScanIterator", func() { return err } - var hashKey = "K_HASHTEST" - var hashSeed = func(n int) error { + hashKey := "K_HASHTEST" + hashSeed := func(n int) error { pipe := client.Pipeline() for i := 1; i <= n; i++ { pipe.HSet(ctx, hashKey, fmt.Sprintf("K%02d", i), "x").Err() diff --git a/ring.go b/ring.go index bc1b7198..c5164e59 100644 --- a/ring.go +++ b/ring.go @@ -477,7 +477,7 @@ func (c *Ring) Subscribe(ctx context.Context, channels ...string) *PubSub { shard, err := c.shards.GetByKey(channels[0]) if err != nil { - //TODO: return PubSub with sticky error + // TODO: return PubSub with sticky error panic(err) } return shard.Client.Subscribe(ctx, channels...) @@ -491,7 +491,7 @@ func (c *Ring) PSubscribe(ctx context.Context, channels ...string) *PubSub { shard, err := c.shards.GetByKey(channels[0]) if err != nil { - //TODO: return PubSub with sticky error + // TODO: return PubSub with sticky error panic(err) } return shard.Client.PSubscribe(ctx, channels...) @@ -672,7 +672,7 @@ func (c *Ring) generalProcessPipeline( func (c *Ring) processShardPipeline( ctx context.Context, hash string, cmds []Cmder, tx bool, ) error { - //TODO: retry? + // TODO: retry? shard, err := c.shards.GetByName(hash) if err != nil { setCmdsErr(cmds, err) diff --git a/script.go b/script.go index 9c884919..07ed482c 100644 --- a/script.go +++ b/script.go @@ -15,9 +15,11 @@ type scripter interface { ScriptLoad(ctx context.Context, script string) *StringCmd } -var _ scripter = (*Client)(nil) -var _ scripter = (*Ring)(nil) -var _ scripter = (*ClusterClient)(nil) +var ( + _ scripter = (*Client)(nil) + _ scripter = (*Ring)(nil) + _ scripter = (*ClusterClient)(nil) +) type Script struct { src, hash string diff --git a/universal.go b/universal.go index 6288d757..8c07ab17 100644 --- a/universal.go +++ b/universal.go @@ -181,9 +181,11 @@ type UniversalClient interface { Close() error } -var _ UniversalClient = (*Client)(nil) -var _ UniversalClient = (*ClusterClient)(nil) -var _ UniversalClient = (*Ring)(nil) +var ( + _ UniversalClient = (*Client)(nil) + _ UniversalClient = (*ClusterClient)(nil) + _ UniversalClient = (*Ring)(nil) +) // NewUniversalClient returns a new multi client. The type of client returned depends // on the following three conditions: diff --git a/universal_test.go b/universal_test.go index 655dd69f..d92ca04f 100644 --- a/universal_test.go +++ b/universal_test.go @@ -37,5 +37,4 @@ var _ = Describe("UniversalClient", func() { }) Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred()) }) - })