浏览代码

more linting fixes

Thibault bui Koechlin 5 年之前
父节点
当前提交
e6cad40ac4
共有 5 个文件被更改,包括 10 次插入17 次删除
  1. 0 7
      pkg/leakybucket/buckets_test.go
  2. 3 3
      pkg/parser/node.go
  3. 3 3
      pkg/parser/runtime.go
  4. 3 3
      pkg/sqlite/stats.go
  5. 1 1
      pkg/time/rate/rate_test.go

+ 0 - 7
pkg/leakybucket/buckets_test.go

@@ -22,11 +22,6 @@ type TestFile struct {
 	Results []types.Event `yaml:"results,omitempty"`
 }
 
-func testBucketStates() {
-	//same as a scenario, but load a bucket state first ?
-
-}
-
 func TestBucket(t *testing.T) {
 
 	var envSetting = os.Getenv("TEST_ONLY")
@@ -261,7 +256,5 @@ POLL_AGAIN:
 			log.Warningf("entry valid at end of loop")
 		}
 	}
-
-	t.Errorf("failed test")
 	return false
 }

+ 3 - 3
pkg/parser/node.go

@@ -399,7 +399,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
 	/* load grok statics */
 	if len(n.Grok.Statics) > 0 {
 		//compile expr statics if present
-		for idx, _ := range n.Grok.Statics {
+		for idx := range n.Grok.Statics {
 			if n.Grok.Statics[idx].ExpValue != "" {
 				n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
 					expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
@@ -412,7 +412,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
 	}
 	/* compile leafs if present */
 	if len(n.SuccessNodes) > 0 {
-		for idx, _ := range n.SuccessNodes {
+		for idx := range n.SuccessNodes {
 			/*propagate debug/stats to child nodes*/
 			if !n.SuccessNodes[idx].Debug && n.Debug {
 				n.SuccessNodes[idx].Debug = true
@@ -432,7 +432,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error {
 		valid = true
 	}
 	/* load statics if present */
-	for idx, _ := range n.Statics {
+	for idx := range n.Statics {
 		if n.Statics[idx].ExpValue != "" {
 			n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
 			if err != nil {

+ 3 - 3
pkg/parser/runtime.go

@@ -128,11 +128,11 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent
 				clog.Warningf("failed to run RunTimeValue : %v", err)
 				continue
 			}
-			switch output.(type) {
+			switch out := output.(type) {
 			case string:
-				value = output.(string)
+				value = out
 			case int:
-				value = strconv.Itoa(output.(int))
+				value = strconv.Itoa(out)
 			default:
 				clog.Fatalf("unexpected return type for RunTimeValue : %T", output)
 				return errors.New("unexpected return type for RunTimeValue")

+ 3 - 3
pkg/sqlite/stats.go

@@ -107,7 +107,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) {
 				bancom["source"] = ba.MeasureSource
 				bancom["events_count"] = "0"
 				bancom["action"] = ba.MeasureType
-				bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second))
+				bancom["until"] = time.Until(ba.Until).Round(time.Second).String()
 				bancom["reason"] = ba.Reason
 				rets = append(rets, bancom)
 				continue
@@ -134,7 +134,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) {
 				bancom["scenario"] = "?"
 				bancom["events_count"] = "0"
 				bancom["action"] = ba.MeasureType
-				bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second))
+				bancom["until"] = time.Until(ba.Until).Round(time.Second).String()
 				bancom["reason"] = ba.Reason
 				rets = append(rets, bancom)
 				continue
@@ -155,7 +155,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) {
 		bancom["events_count"] = fmt.Sprintf("%d", evtCount)
 		bancom["action"] = ba.MeasureType
 		bancom["source"] = ba.MeasureSource
-		bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second))
+		bancom["until"] = time.Until(ba.Until).Round(time.Second).String()
 		bancom["reason"] = so.Scenario
 		rets = append(rets, bancom)
 	}

+ 1 - 1
pkg/time/rate/rate_test.go

@@ -400,7 +400,7 @@ type wait struct {
 func runWait(t *testing.T, lim *Limiter, w wait) {
 	start := time.Now()
 	err := lim.WaitN(w.ctx, w.n)
-	delay := time.Now().Sub(start)
+	delay := time.Since(start)
 	if (w.nilErr && err != nil) || (!w.nilErr && err == nil) || w.delay != dFromDuration(delay) {
 		errString := "<nil>"
 		if !w.nilErr {