Procházet zdrojové kódy

refactor: remove unnecessary conversion (#1876)

* refactor: remove unnecessary conversion

- fix typos
- use stdvars

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

* fix test error

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

---------

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>
Jason Lyu před 1 rokem
rodič
revize
db1facd056

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 26 - 26
internal/converter/protobuf/fieldConverterSingleton.go


+ 1 - 1
internal/pkg/httpx/http.go

@@ -183,7 +183,7 @@ func ReadFile(uri string) (io.ReadCloser, error) {
 		src = srcFile
 	case "http", "https":
 		// Get the data
-		timeout := time.Duration(5 * time.Minute)
+		timeout := 5 * time.Minute
 		client := &http.Client{
 			Timeout: timeout,
 			Transport: &http.Transport{

+ 5 - 5
internal/server/middleware/auth_test.go

@@ -17,7 +17,7 @@ func genToken(signKeyName, issuer, aud string) string {
 
 func Test_AUTH(t *testing.T) {
 	nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		w.WriteHeader(200)
+		w.WriteHeader(http.StatusOK)
 	})
 
 	handler := Auth(nextHandler)
@@ -35,7 +35,7 @@ func Test_AUTH(t *testing.T) {
 		{
 			name:     "token right",
 			args:     args{th: genToken("sample_key", "sample_key.pub", "eKuiper")},
-			req:      httptest.NewRequest("GET", "http://127.0.0.1:9081/streams", nil),
+			req:      httptest.NewRequest(http.MethodGet, "http://127.0.0.1:9081/streams", nil),
 			res:      httptest.NewRecorder(),
 			wantCode: 200,
 		},
@@ -43,21 +43,21 @@ func Test_AUTH(t *testing.T) {
 		{
 			name:     "audience not right",
 			args:     args{th: genToken("sample_key", "sample_key.pub", "Neuron")},
-			req:      httptest.NewRequest("GET", "http://127.0.0.1:9081/streams", nil),
+			req:      httptest.NewRequest(http.MethodGet, "http://127.0.0.1:9081/streams", nil),
 			res:      httptest.NewRecorder(),
 			wantCode: 401,
 		},
 		{
 			name:     "no token",
 			args:     args{th: ""},
-			req:      httptest.NewRequest("GET", "http://127.0.0.1:9081/streams", nil),
+			req:      httptest.NewRequest(http.MethodGet, "http://127.0.0.1:9081/streams", nil),
 			res:      httptest.NewRecorder(),
 			wantCode: 401,
 		},
 		{
 			name:     "no need token path",
 			args:     args{th: ""},
-			req:      httptest.NewRequest("GET", "http://127.0.0.1:9081/ping", nil),
+			req:      httptest.NewRequest(http.MethodGet, "http://127.0.0.1:9081/ping", nil),
 			res:      httptest.NewRecorder(),
 			wantCode: 200,
 		},

+ 2 - 2
internal/server/os.go

@@ -130,8 +130,8 @@ func parseLine(line string) (key string, value string, err error) {
 
 	// Handle double quotes
 	if strings.ContainsAny(value, `"`) {
-		first := string(value[0:1])
-		last := string(value[len(value)-1:])
+		first := value[0:1]
+		last := value[len(value)-1:]
 
 		if first == last && strings.ContainsAny(first, `"'`) {
 			value = strings.TrimPrefix(value, `'`)

+ 1 - 1
internal/server/plugin_init.go

@@ -255,7 +255,7 @@ func fetchPluginList(t plugin.PluginType, hosts, os, arch string) (result map[st
 
 	if hosts == "" || ptype == "" || os == "" {
 		logger.Errorf("Invalid parameter value: hosts %s, ptype %s or os: %s should not be empty.", hosts, ptype, os)
-		return nil, fmt.Errorf("invalid configruation for plugin host in kuiper.yaml")
+		return nil, fmt.Errorf("invalid configuration for plugin host in kuiper.yaml")
 	}
 	result = make(map[string]string)
 	hostsArr := strings.Split(hosts, ",")

+ 2 - 2
internal/server/rest_test.go

@@ -254,7 +254,7 @@ func Test_rulesManageHandler(t *testing.T) {
 	w1 = httptest.NewRecorder()
 	r.ServeHTTP(w1, req1)
 
-	if w1.Result().StatusCode != 200 {
+	if w1.Result().StatusCode != http.StatusOK {
 		t.Errorf("Expect\t%v\nBut got\t%v", 200, w1.Result().StatusCode)
 	}
 
@@ -266,7 +266,7 @@ func Test_rulesManageHandler(t *testing.T) {
 	w1 = httptest.NewRecorder()
 	r.ServeHTTP(w1, req1)
 
-	if w1.Result().StatusCode != 400 {
+	if w1.Result().StatusCode != http.StatusBadRequest {
 		t.Errorf("Expect\t%v\nBut got\t%v", 200, w1.Result().StatusCode)
 	}
 

+ 1 - 1
internal/topo/planner/planner_graph.go

@@ -254,7 +254,7 @@ func PlanByGraph(rule *api.Rule) (*topo.Topo, error) {
 		} else {
 			nodeIO, ok := graph.OpIO[strings.ToLower(gn.NodeType)]
 			if !ok {
-				return nil, fmt.Errorf("can't find the io definiton for node type %s", gn.NodeType)
+				return nil, fmt.Errorf("can't find the io definition for node type %s", gn.NodeType)
 			}
 			dataInCondition := nodeIO[0]
 			indim := reversedEdges[n]

+ 1 - 2
internal/topo/transform/func.go

@@ -23,7 +23,6 @@ import (
 	"fmt"
 	"reflect"
 	"strconv"
-	"text/template"
 
 	"github.com/Masterminds/sprig/v3"
 
@@ -31,7 +30,7 @@ import (
 )
 
 func RegisterAdditionalFuncs() {
-	conf.FuncMap = template.FuncMap(sprig.FuncMap())
+	conf.FuncMap = sprig.FuncMap()
 	conf.FuncMap["json"] = conf.FuncMap["toJson"]
 	conf.FuncMap["base64"] = Base64Encode
 }

+ 1 - 1
internal/xsql/row_test.go

@@ -118,7 +118,7 @@ func TestCollectionRow(t *testing.T) {
 }
 
 func TestTupleRow(t *testing.T) {
-	// boradcast(clone) -> set -> broadcast -> set -> compare
+	// broadcast(clone) -> set -> broadcast -> set -> compare
 	tests := []struct {
 		rowO TupleRow
 		// The multiple values to set or alias; The first value is set in the first broadcast. the next values are set in the second broadcast.

+ 2 - 2
pkg/cast/cast.go

@@ -204,7 +204,7 @@ func ToInt16(input interface{}, sn Strictness) (int16, error) {
 	case int32:
 		return int16(s), nil
 	case int16:
-		return int16(s), nil
+		return s, nil
 	case int8:
 		return int16(s), nil
 	case uint:
@@ -333,7 +333,7 @@ func ToInt64(input interface{}, sn Strictness) (int64, error) {
 		if sn == CONVERT_ALL {
 			v, err := strconv.ParseInt(s, 0, 0)
 			if err == nil {
-				return int64(v), nil
+				return v, nil
 			}
 		}
 	case bool:

+ 1 - 1
test/edgex/pub.go

@@ -223,7 +223,7 @@ func pubMetaSource() {
 					fmt.Println(string(data))
 				}
 
-				env := types.NewMessageEnvelope([]byte(data), context.Background())
+				env := types.NewMessageEnvelope(data, context.Background())
 				env.ContentType = "application/json"
 
 				if e := msgClient.Publish(env, "events"); e != nil {