Skip to content

Commit ee6720a

Browse files
committed
fix issues reported by go vet
1 parent 2d28d0b commit ee6720a

2 files changed

Lines changed: 33 additions & 26 deletions

File tree

jsonpath.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"fmt"
55
"github.com/mohae/utilitybelt/deepcopy"
66
//"golang.org/x/tools/go/types"
7+
"errors"
78
"go/token"
89
"go/types"
910
"reflect"
1011
"strconv"
1112
"strings"
12-
"errors"
1313
)
1414

1515
var ErrGetFromNullObj = errors.New("get attribute from null object")
@@ -417,9 +417,12 @@ func parse_filter(filter string) (lp string, op string, rp string, err error) {
417417
str_embrace = true
418418
} else {
419419
switch stage {
420-
case 0: lp = tmp
421-
case 1: op = tmp
422-
case 2: rp = tmp
420+
case 0:
421+
lp = tmp
422+
case 1:
423+
op = tmp
424+
case 2:
425+
rp = tmp
423426
}
424427
tmp = ""
425428
}
@@ -429,15 +432,18 @@ func parse_filter(filter string) (lp string, op string, rp string, err error) {
429432
continue
430433
}
431434
switch stage {
432-
case 0: lp = tmp
433-
case 1: op = tmp
434-
case 2: rp = tmp
435+
case 0:
436+
lp = tmp
437+
case 1:
438+
op = tmp
439+
case 2:
440+
rp = tmp
435441
}
436442
tmp = ""
437443

438444
stage += 1
439445
if stage > 2 {
440-
return "", "", "", errors.New(fmt.Sprintf("invalid char at %d: `%s`", idx, c))
446+
return "", "", "", errors.New(fmt.Sprintf("invalid char at %d: `%c`", idx, c))
441447
}
442448
default:
443449
tmp += string(c)
@@ -448,8 +454,10 @@ func parse_filter(filter string) (lp string, op string, rp string, err error) {
448454
case 0:
449455
lp = tmp
450456
op = "exists"
451-
case 1: op = tmp
452-
case 2: rp = tmp
457+
case 1:
458+
op = tmp
459+
case 2:
460+
rp = tmp
453461
}
454462
tmp = ""
455463
}
@@ -528,11 +536,11 @@ func eval_filter(obj, root interface{}, lp, op, rp string) (res bool, err error)
528536

529537
func isNumber(o interface{}) bool {
530538
switch v := o.(type) {
531-
case int,int8,int16,int32,int64:
539+
case int, int8, int16, int32, int64:
532540
return true
533-
case uint,uint8,uint16,uint32,uint64:
541+
case uint, uint8, uint16, uint32, uint64:
534542
return true
535-
case float32,float64:
543+
case float32, float64:
536544
return true
537545
case string:
538546
_, err := strconv.ParseFloat(v, 64)

jsonpath_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func Test_jsonpath_JsonPathLookup_1(t *testing.T) {
110110
func Test_jsonpath_JsonPathLookup_filter(t *testing.T) {
111111
res, err := JsonPathLookup(json_data, "$.store.book[?(@.isbn)].isbn")
112112
t.Log(err, res)
113-
return
113+
114114
if res_v, ok := res.([]interface{}); ok != true {
115115
if res_v[0].(string) != "0-553-21311-3" || res_v[1].(string) != "0-395-19395-8" {
116116
t.Errorf("error: %v", res)
@@ -360,7 +360,7 @@ func Test_jsonpath_parse_token(t *testing.T) {
360360
if args_v, ok := args.([]int); ok == true {
361361
for i, v := range args_v {
362362
if v != exp_args.([]int)[i] {
363-
t.Errorf("ERROR: different args: [%d], (got)%v != (exp)%v", v, exp_args.([]int)[i])
363+
t.Errorf("ERROR: different args: [%d], (got)%v != (exp)%v", i, v, exp_args.([]int)[i])
364364
return
365365
}
366366
}
@@ -850,24 +850,24 @@ var tcase_cmp_any = []map[string]interface{}{
850850
"op": "=~",
851851
"exp": false,
852852
"err": "op should only be <, <=, ==, >= and >",
853-
},{
853+
}, {
854854
"obj1": ifc1,
855855
"obj2": ifc1,
856856
"op": "==",
857857
"exp": true,
858-
"err": nil,
859-
},{
858+
"err": nil,
859+
}, {
860860
"obj1": ifc2,
861861
"obj2": ifc2,
862862
"op": "==",
863863
"exp": true,
864-
"err": nil,
865-
},{
864+
"err": nil,
865+
}, {
866866
"obj1": 20,
867867
"obj2": "100",
868-
"op": ">",
869-
"exp": false,
870-
"err": nil,
868+
"op": ">",
869+
"exp": false,
870+
"err": nil,
871871
},
872872
}
873873

@@ -880,7 +880,7 @@ func Test_jsonpath_cmp_any(t *testing.T) {
880880
exp_err := tcase["err"]
881881
if exp_err != nil {
882882
if err == nil {
883-
t.Errorf("idx: error not raised: %v(exp)", idx, exp_err)
883+
t.Errorf("idx: %d error not raised: %v(exp)", idx, exp_err)
884884
break
885885
}
886886
} else {
@@ -935,7 +935,6 @@ func Test_jsonpath_string_equal(t *testing.T) {
935935
"expensive": 10
936936
}`
937937

938-
939938
var j interface{}
940939

941940
json.Unmarshal([]byte(data), &j)
@@ -982,4 +981,4 @@ func Test_jsonpath_num_cmp(t *testing.T) {
982981
t.Fatal("should return [], got: ", arr)
983982
}
984983

985-
}
984+
}

0 commit comments

Comments
 (0)