Skip to content

Commit 02a9c81

Browse files
committed
Fix golangci-lint check
1 parent e3c1e88 commit 02a9c81

File tree

9 files changed

+26
-27
lines changed

9 files changed

+26
-27
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ linters:
2222
- exhaustivestruct
2323
- wrapcheck
2424
- errorlint
25+
- cyclop
26+
- forcetypeassert

cluster.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ func (c *clusterNodes) Close() error {
295295

296296
func (c *clusterNodes) Addrs() ([]string, error) {
297297
var addrs []string
298+
298299
c.mu.RLock()
299-
closed := c.closed
300+
closed := c.closed //nolint:ifshort
300301
if !closed {
301302
if len(c.activeAddrs) > 0 {
302303
addrs = c.activeAddrs
@@ -649,14 +650,15 @@ func (c *clusterStateHolder) LazyReload() {
649650

650651
func (c *clusterStateHolder) Get(ctx context.Context) (*clusterState, error) {
651652
v := c.state.Load()
652-
if v != nil {
653-
state := v.(*clusterState)
654-
if time.Since(state.createdAt) > 10*time.Second {
655-
c.LazyReload()
656-
}
657-
return state, nil
653+
if v == nil {
654+
return c.Reload(ctx)
658655
}
659-
return c.Reload(ctx)
656+
657+
state := v.(*clusterState)
658+
if time.Since(state.createdAt) > 10*time.Second {
659+
c.LazyReload()
660+
}
661+
return state, nil
660662
}
661663

662664
func (c *clusterStateHolder) ReloadOrGet(ctx context.Context) (*clusterState, error) {

commands.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,12 +1989,10 @@ func (c cmdable) ZIncrBy(ctx context.Context, key string, increment float64, mem
19891989
}
19901990

19911991
func (c cmdable) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd {
1992-
args := make([]interface{}, 3+len(store.Keys))
1993-
args[0] = "zinterstore"
1994-
args[1] = destination
1995-
args[2] = len(store.Keys)
1996-
for i, key := range store.Keys {
1997-
args[3+i] = key
1992+
args := make([]interface{}, 0, 3+len(store.Keys))
1993+
args = append(args, "zinterstore", destination, len(store.Keys))
1994+
for _, key := range store.Keys {
1995+
args = append(args, key)
19981996
}
19991997
if len(store.Weights) > 0 {
20001998
args = append(args, "weights")
@@ -2237,12 +2235,10 @@ func (c cmdable) ZScore(ctx context.Context, key, member string) *FloatCmd {
22372235
}
22382236

22392237
func (c cmdable) ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd {
2240-
args := make([]interface{}, 3+len(store.Keys))
2241-
args[0] = "zunionstore"
2242-
args[1] = dest
2243-
args[2] = len(store.Keys)
2244-
for i, key := range store.Keys {
2245-
args[3+i] = key
2238+
args := make([]interface{}, 0, 3+len(store.Keys))
2239+
args = append(args, "zunionstore", dest, len(store.Keys))
2240+
for _, key := range store.Keys {
2241+
args = append(args, key)
22462242
}
22472243
if len(store.Weights) > 0 {
22482244
args = append(args, "weights")

internal/pool/pool_sticky.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ func (p *StickyConnPool) Reset(ctx context.Context) error {
172172

173173
func (p *StickyConnPool) badConnError() error {
174174
if v := p._badConnError.Load(); v != nil {
175-
err := v.(BadConnError)
176-
if err.wrapped != nil {
175+
if err := v.(BadConnError); err.wrapped != nil {
177176
return err
178177
}
179178
}

internal/proto/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r *Reader) readLine() ([]byte, error) {
8383
return nil, err
8484
}
8585

86-
full = append(full, b...)
86+
full = append(full, b...) //nolint:makezero
8787
b = full
8888
}
8989
if len(b) <= 2 || b[len(b)-1] != '\n' || b[len(b)-2] != '\r' {

internal/proto/scan.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
)
1111

1212
// Scan parses bytes `b` to `v` with appropriate type.
13-
// nolint: gocyclo
1413
func Scan(b []byte, v interface{}) error {
1514
switch v := v.(type) {
1615
case nil:

pubsub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func mapKeys(m map[string]struct{}) []string {
118118
i := 0
119119
for k := range m {
120120
s[i] = k
121-
i++
121+
i++ // nolint:wastedassign
122122
}
123123
return s
124124
}

redis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ func (c *baseClient) withConn(
305305
c.releaseConn(ctx, cn, err)
306306
}()
307307

308-
done := ctx.Done()
308+
done := ctx.Done() //nolint:ifshort
309+
309310
if done == nil {
310311
err = fn(ctx, cn)
311312
return err

sentinel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ func parseSlaveAddrs(addrs []interface{}, keepDisconnected bool) []string {
625625

626626
func (c *sentinelFailover) trySwitchMaster(ctx context.Context, addr string) {
627627
c.mu.RLock()
628-
currentAddr := c._masterAddr
628+
currentAddr := c._masterAddr //nolint:ifshort
629629
c.mu.RUnlock()
630630

631631
if addr == currentAddr {

0 commit comments

Comments
 (0)