Browse Source

fix: pre-correct lint detected errors (#1955)

* fix(extensions): pre-correct lint detected errors

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>

* fix: add nolint annotation

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>

* fix(tools/kubernetes): pre-correct lint detected errors

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>

---------

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>
Jason Lyu 1 year ago
parent
commit
fd1f122931

+ 4 - 4
extensions/functions/geohash/geohash.go

@@ -210,7 +210,7 @@ func (r *geohashDecode) Exec(args []interface{}, _ api.FunctionContext) (interfa
 
 func (r *geohashDecodeInt) Exec(args []interface{}, _ api.FunctionContext) (interface{}, bool) {
 	hash, ok := args[0].(uint64)
-	if !ok || 0 > hash {
+	if !ok {
 		return fmt.Errorf("arg[0] is not a bigint, got %v", args[0]), false
 	}
 	la, lo := geohash.DecodeInt(hash)
@@ -230,7 +230,7 @@ func (r *geohashBoundingBox) Exec(args []interface{}, _ api.FunctionContext) (in
 
 func (r *geohashBoundingBoxInt) Exec(args []interface{}, _ api.FunctionContext) (interface{}, bool) {
 	hash, ok := args[0].(uint64)
-	if !ok || 0 > hash {
+	if !ok {
 		return fmt.Errorf("arg[0] is not a bigint, got %v", args[0]), false
 	}
 	return geohash.BoundingBoxInt(hash), true
@@ -260,7 +260,7 @@ func (r *geohashNeighbor) Exec(args []interface{}, _ api.FunctionContext) (inter
 
 func (r *geohashNeighborInt) Exec(args []interface{}, _ api.FunctionContext) (interface{}, bool) {
 	hash, ok := args[0].(uint64)
-	if !ok || 0 > hash {
+	if !ok {
 		return fmt.Errorf("arg[0] is not a bigint, got %v", args[0]), false
 	}
 	var directionCode geohash.Direction
@@ -289,7 +289,7 @@ func (r *geohashNeighbors) Exec(args []interface{}, _ api.FunctionContext) (inte
 
 func (r *geohashNeighborsInt) Exec(args []interface{}, _ api.FunctionContext) (interface{}, bool) {
 	hash, ok := args[0].(uint64)
-	if !ok || 0 > hash {
+	if !ok {
 		return fmt.Errorf("arg[0] is not a bigint, got %v", args[0]), false
 	}
 	return geohash.NeighborsInt(hash), true

+ 4 - 5
extensions/sinks/image/image.go

@@ -49,10 +49,10 @@ func (m *imageSink) Configure(props map[string]interface{}) error {
 	}
 
 	if i, ok := props["path"]; ok {
-		if i, ok := i.(string); ok {
-			m.path = i
+		if ii, ok := i.(string); ok {
+			m.path = ii
 		} else {
-			return fmt.Errorf("%s image type is not supported", i)
+			return fmt.Errorf("%v image type is not supported", i)
 		}
 	} else {
 		return fmt.Errorf("Field not found path.")
@@ -201,9 +201,8 @@ func (m *imageSink) Collect(ctx api.StreamContext, item interface{}) error {
 	case map[string]interface{}:
 		return m.saveFiles(v)
 	default:
-		fmt.Errorf("image sink receive invalid data %v", item)
+		return fmt.Errorf("image sink receive invalid data %v", item)
 	}
-	return nil
 }
 
 func (m *imageSink) Close(ctx api.StreamContext) error {

+ 6 - 6
extensions/sinks/influx2/influx2_test.go

@@ -37,7 +37,7 @@ func TestConfig(t *testing.T) {
 				"bucket":      "bucket_one",
 				"tagKey":      "tag",
 				"tagValue":    "value",
-				"fields":      "temperature",
+				"fields":      []interface{}{"temperature"},
 			},
 			expected: &influxSink2{
 				addr:         "http://192.168.0.3:8086",
@@ -47,7 +47,7 @@ func TestConfig(t *testing.T) {
 				bucket:       "bucket_one",
 				tagKey:       "tag",
 				tagValue:     "value",
-				fields:       "temperature",
+				fields:       []string{"temperature"},
 				cli:          nil,
 				fieldMap:     nil,
 				hasTransform: false,
@@ -62,7 +62,7 @@ func TestConfig(t *testing.T) {
 				"bucket":       "bucket_one",
 				"tagKey":       "tag",
 				"tagValue":     "value",
-				"fields":       "temperature",
+				"fields":       []interface{}{"temperature"},
 				"dataTemplate": "",
 			},
 			expected: &influxSink2{
@@ -73,7 +73,7 @@ func TestConfig(t *testing.T) {
 				bucket:       "bucket_one",
 				tagKey:       "tag",
 				tagValue:     "value",
-				fields:       "temperature",
+				fields:       []string{"temperature"},
 				cli:          nil,
 				fieldMap:     nil,
 				hasTransform: false,
@@ -88,7 +88,7 @@ func TestConfig(t *testing.T) {
 				"bucket":       "bucket_one",
 				"tagKey":       "tag",
 				"tagValue":     "value",
-				"fields":       "temperature",
+				"fields":       []interface{}{"temperature"},
 				"dataTemplate": "{{funcname .arg1 .arg2}}",
 			},
 			expected: &influxSink2{
@@ -99,7 +99,7 @@ func TestConfig(t *testing.T) {
 				bucket:       "bucket_one",
 				tagKey:       "tag",
 				tagValue:     "value",
-				fields:       "temperature",
+				fields:       []string{"temperature"},
 				cli:          nil,
 				fieldMap:     nil,
 				hasTransform: true,

+ 1 - 2
extensions/sinks/sql/sql.go

@@ -20,11 +20,10 @@ import (
 	"reflect"
 	"strings"
 
-	"github.com/lf-edge/ekuiper/internal/topo/transform"
-
 	"github.com/lf-edge/ekuiper/extensions/sqldatabase"
 	"github.com/lf-edge/ekuiper/extensions/sqldatabase/driver"
 	"github.com/lf-edge/ekuiper/extensions/util"
+	"github.com/lf-edge/ekuiper/internal/topo/transform"
 	"github.com/lf-edge/ekuiper/pkg/api"
 	"github.com/lf-edge/ekuiper/pkg/ast"
 	"github.com/lf-edge/ekuiper/pkg/cast"

+ 2 - 1
extensions/sinks/sql/sql_test.go

@@ -18,11 +18,12 @@ import (
 	"database/sql"
 	"database/sql/driver"
 	"fmt"
-	"github.com/stretchr/testify/assert"
 	"os"
 	"reflect"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
+
 	"github.com/lf-edge/ekuiper/extensions/sqldatabase"
 	econf "github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/topo/context"

+ 1 - 1
sdk/go/runtime/plugin.go

@@ -179,7 +179,7 @@ func Start(args []string, conf *PluginConfig) {
 	}()
 	// Stop the whole plugin
 	sigint := make(chan os.Signal, 1)
-	signal.Notify(sigint, os.Interrupt, syscall.SIGTERM, syscall.SIGKILL)
+	signal.Notify(sigint, os.Interrupt, syscall.SIGTERM, syscall.SIGKILL) //nolint:staticcheck
 	<-sigint
 	logger.Infof("stopping plugin %s", conf.Name)
 	os.Exit(0)

+ 9 - 7
tools/kubernetes/util/util.go

@@ -17,6 +17,7 @@ package util
 import (
 	"encoding/json"
 	"fmt"
+	"net/http"
 	"os"
 	"path"
 	"strings"
@@ -47,17 +48,17 @@ func (c *command) call(host string) bool {
 	var err error
 	head := host + c.Url
 	body, _ := json.Marshal(c.Data)
-	switch c.Method {
-	case "post", "POST":
+	switch strings.ToUpper(c.Method) {
+	case http.MethodPost:
 		resp, err = kconf.Post(head, string(body))
 		break
-	case "get", "GET":
+	case http.MethodGet:
 		resp, err = kconf.Get(head)
 		break
-	case "delete", "DELETE":
+	case http.MethodDelete:
 		resp, err = kconf.Delete(head)
 		break
-	case "put", "PUT":
+	case http.MethodPut:
 		resp, err = kconf.Put(head, string(body))
 		break
 	default:
@@ -207,10 +208,11 @@ func (s *server) watchFolders() {
 	conf := kconf.GetConf()
 	s.processDir()
 	s.printLogs()
-	chTime := time.Tick(time.Second * time.Duration(conf.GetIntervalTime()))
+	chTimer := time.NewTicker(time.Second * time.Duration(conf.GetIntervalTime()))
+	defer chTimer.Stop()
 	for {
 		select {
-		case <-chTime:
+		case <-chTimer.C:
 			s.processDir()
 			s.printLogs()
 		}