소스 검색

fix golint issues

kevin 3 년 전
부모
커밋
fe3739b7f3

+ 1 - 2
core/breaker/googlebreaker_test.go

@@ -2,7 +2,6 @@ package breaker
 
 import (
 	"errors"
-	"math"
 	"math/rand"
 	"testing"
 	"time"
@@ -157,7 +156,7 @@ func TestGoogleBreakerSelfProtection(t *testing.T) {
 	t.Run("total request > 100, total < 2 * success", func(t *testing.T) {
 		b := getGoogleBreaker()
 		size := rand.Intn(10000)
-		accepts := int(math.Ceil(float64(size))) + 1
+		accepts := size + 1
 		markSuccess(b, accepts)
 		markFailed(b, size-accepts)
 		assert.Nil(t, b.accept())

+ 9 - 12
core/collection/cache.go

@@ -277,18 +277,15 @@ func (cs *cacheStat) statLoop() {
 	ticker := time.NewTicker(statInterval)
 	defer ticker.Stop()
 
-	for {
-		select {
-		case <-ticker.C:
-			hit := atomic.SwapUint64(&cs.hit, 0)
-			miss := atomic.SwapUint64(&cs.miss, 0)
-			total := hit + miss
-			if total == 0 {
-				continue
-			}
-			percent := 100 * float32(hit) / float32(total)
-			logx.Statf("cache(%s) - qpm: %d, hit_ratio: %.1f%%, elements: %d, hit: %d, miss: %d",
-				cs.name, total, percent, cs.sizeCallback(), hit, miss)
+	for range ticker.C {
+		hit := atomic.SwapUint64(&cs.hit, 0)
+		miss := atomic.SwapUint64(&cs.miss, 0)
+		total := hit + miss
+		if total == 0 {
+			continue
 		}
+		percent := 100 * float32(hit) / float32(total)
+		logx.Statf("cache(%s) - qpm: %d, hit_ratio: %.1f%%, elements: %d, hit: %d, miss: %d",
+			cs.name, total, percent, cs.sizeCallback(), hit, miss)
 	}
 }

+ 4 - 2
core/contextx/valueonlycontext_test.go

@@ -45,9 +45,11 @@ func TestContextDeadline(t *testing.T) {
 		t.Fatal("ValueOnlyContext: context should not have timed out")
 	}
 
-	c, _ = context.WithDeadline(context.Background(), time.Now().Add(10*time.Millisecond))
+	c, cancel = context.WithDeadline(context.Background(), time.Now().Add(10*time.Millisecond))
+	cancel()
 	o = ValueOnlyFrom(c)
-	c, _ = context.WithDeadline(o, time.Now().Add(20*time.Millisecond))
+	c, cancel = context.WithDeadline(o, time.Now().Add(20*time.Millisecond))
+	defer cancel()
 	select {
 	case <-time.After(100 * time.Millisecond):
 		t.Fatal("ValueOnlyContext+Deadline: context should have timed out")

+ 1 - 3
core/executors/bulkexecutor_test.go

@@ -86,9 +86,7 @@ func TestBuldExecutorFlushSlowTasks(t *testing.T) {
 		time.Sleep(time.Millisecond * 100)
 		lock.Lock()
 		defer lock.Unlock()
-		for _, i := range tasks {
-			result = append(result, i)
-		}
+		result = append(result, tasks...)
 	}, WithBulkTasks(1000))
 	for i := 0; i < total; i++ {
 		assert.Nil(t, exec.Add(i))

+ 4 - 7
core/limit/tokenlimit.go

@@ -153,13 +153,10 @@ func (lim *TokenLimiter) waitForRedis() {
 		lim.rescueLock.Unlock()
 	}()
 
-	for {
-		select {
-		case <-ticker.C:
-			if lim.store.Ping() {
-				atomic.StoreUint32(&lim.redisAlive, 1)
-				return
-			}
+	for range ticker.C {
+		if lim.store.Ping() {
+			atomic.StoreUint32(&lim.redisAlive, 1)
+			return
 		}
 	}
 }

+ 4 - 2
core/logx/logs_test.go

@@ -229,8 +229,10 @@ func TestSetup(t *testing.T) {
 
 func TestDisable(t *testing.T) {
 	Disable()
-	WithKeepDays(1)
-	WithGzip()
+
+	var opt logOptions
+	WithKeepDays(1)(&opt)
+	WithGzip()(&opt)
 	assert.Nil(t, Close())
 	writeConsole = false
 	assert.Nil(t, Close())

+ 1 - 1
core/logx/syslog_test.go

@@ -15,7 +15,7 @@ const testlog = "Stay hungry, stay foolish."
 func TestCollectSysLog(t *testing.T) {
 	CollectSysLog()
 	content := getContent(captureOutput(func() {
-		log.Printf(testlog)
+		log.Print(testlog)
 	}))
 	assert.True(t, strings.Contains(content, testlog))
 }

+ 11 - 14
core/stores/cache/cachestat.go

@@ -48,20 +48,17 @@ func (cs *CacheStat) statLoop() {
 	ticker := time.NewTicker(statInterval)
 	defer ticker.Stop()
 
-	for {
-		select {
-		case <-ticker.C:
-			total := atomic.SwapUint64(&cs.Total, 0)
-			if total == 0 {
-				continue
-			}
-
-			hit := atomic.SwapUint64(&cs.Hit, 0)
-			percent := 100 * float32(hit) / float32(total)
-			miss := atomic.SwapUint64(&cs.Miss, 0)
-			dbf := atomic.SwapUint64(&cs.DbFails, 0)
-			logx.Statf("dbcache(%s) - qpm: %d, hit_ratio: %.1f%%, hit: %d, miss: %d, db_fails: %d",
-				cs.name, total, percent, hit, miss, dbf)
+	for range ticker.C {
+		total := atomic.SwapUint64(&cs.Total, 0)
+		if total == 0 {
+			continue
 		}
+
+		hit := atomic.SwapUint64(&cs.Hit, 0)
+		percent := 100 * float32(hit) / float32(total)
+		miss := atomic.SwapUint64(&cs.Miss, 0)
+		dbf := atomic.SwapUint64(&cs.DbFails, 0)
+		logx.Statf("dbcache(%s) - qpm: %d, hit_ratio: %.1f%%, hit: %d, miss: %d, db_fails: %d",
+			cs.name, total, percent, hit, miss, dbf)
 	}
 }

+ 6 - 6
core/trace/propagator_test.go

@@ -18,7 +18,7 @@ func TestHttpPropagator_Extract(t *testing.T) {
 	assert.Equal(t, "trace", carrier.Get(traceIdKey))
 	assert.Equal(t, "span", carrier.Get(spanIdKey))
 
-	carrier, err = Extract(HttpFormat, req)
+	_, err = Extract(HttpFormat, req)
 	assert.Equal(t, ErrInvalidCarrier, err)
 }
 
@@ -31,7 +31,7 @@ func TestHttpPropagator_Inject(t *testing.T) {
 	assert.Equal(t, "trace", carrier.Get(traceIdKey))
 	assert.Equal(t, "span", carrier.Get(spanIdKey))
 
-	carrier, err = Inject(HttpFormat, req)
+	_, err = Inject(HttpFormat, req)
 	assert.Equal(t, ErrInvalidCarrier, err)
 }
 
@@ -45,9 +45,9 @@ func TestGrpcPropagator_Extract(t *testing.T) {
 	assert.Equal(t, "trace", carrier.Get(traceIdKey))
 	assert.Equal(t, "span", carrier.Get(spanIdKey))
 
-	carrier, err = Extract(GrpcFormat, 1)
+	_, err = Extract(GrpcFormat, 1)
 	assert.Equal(t, ErrInvalidCarrier, err)
-	carrier, err = Extract(nil, 1)
+	_, err = Extract(nil, 1)
 	assert.Equal(t, ErrInvalidCarrier, err)
 }
 
@@ -61,8 +61,8 @@ func TestGrpcPropagator_Inject(t *testing.T) {
 	assert.Equal(t, "trace", carrier.Get(traceIdKey))
 	assert.Equal(t, "span", carrier.Get(spanIdKey))
 
-	carrier, err = Inject(GrpcFormat, 1)
+	_, err = Inject(GrpcFormat, 1)
 	assert.Equal(t, ErrInvalidCarrier, err)
-	carrier, err = Inject(nil, 1)
+	_, err = Inject(nil, 1)
 	assert.Equal(t, ErrInvalidCarrier, err)
 }