Skip to content

Commit 1246eb3

Browse files
Go 1.18 as minimum requirement
1 parent ba20aad commit 1246eb3

15 files changed

+172
-167
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
go: ['1.16', '1.18', '1.19', '1.20', '1.21']
8+
go: ['1.18', '1.19', '1.20', '1.21', '1.22', '1.23']
99
name: Running with Go ${{ matrix.go }}
1010
steps:
1111
- name: Install Go

arrays.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ func (e ErrReduceDataType) Error() string {
1212
return fmt.Sprintf("The type \"%s\" is not supported", e.dataType)
1313
}
1414

15-
func filter(values, data interface{}) interface{} {
16-
parsed := values.([]interface{})
15+
func filter(values, data any) any {
16+
parsed := values.([]any)
1717

18-
var subject interface{}
18+
var subject any
1919

2020
if isSlice(parsed[0]) {
2121
subject = parsed[0]
@@ -25,15 +25,15 @@ func filter(values, data interface{}) interface{} {
2525
subject = apply(parsed[0], data)
2626
}
2727

28-
result := make([]interface{}, 0)
28+
result := make([]any, 0)
2929

3030
if subject == nil {
3131
return result
3232
}
3333

3434
logic := solveVars(parsed[1], data)
3535

36-
for _, value := range subject.([]interface{}) {
36+
for _, value := range subject.([]any) {
3737
v := parseValues(logic, value)
3838

3939
if isTrue(v) {
@@ -44,10 +44,10 @@ func filter(values, data interface{}) interface{} {
4444
return result
4545
}
4646

47-
func _map(values, data interface{}) interface{} {
48-
parsed := values.([]interface{})
47+
func _map(values, data any) any {
48+
parsed := values.([]any)
4949

50-
var subject interface{}
50+
var subject any
5151

5252
if isSlice(parsed[0]) {
5353
subject = parsed[0]
@@ -57,15 +57,15 @@ func _map(values, data interface{}) interface{} {
5757
subject = apply(parsed[0], data)
5858
}
5959

60-
result := make([]interface{}, 0)
60+
result := make([]any, 0)
6161

6262
if subject == nil {
6363
return result
6464
}
6565

6666
logic := solveVars(parsed[1], data)
6767

68-
for _, value := range subject.([]interface{}) {
68+
for _, value := range subject.([]any) {
6969
v := parseValues(logic, value)
7070

7171
if isTrue(v) || isNumber(v) || isBool(v) {
@@ -76,10 +76,10 @@ func _map(values, data interface{}) interface{} {
7676
return result
7777
}
7878

79-
func reduce(values, data interface{}) interface{} {
80-
parsed := values.([]interface{})
79+
func reduce(values, data any) any {
80+
parsed := values.([]any)
8181

82-
var subject interface{}
82+
var subject any
8383

8484
if isSlice(parsed[0]) {
8585
subject = parsed[0]
@@ -94,7 +94,7 @@ func reduce(values, data interface{}) interface{} {
9494
}
9595

9696
var (
97-
accumulator interface{}
97+
accumulator any
9898
valueType string
9999
)
100100

@@ -120,13 +120,13 @@ func reduce(values, data interface{}) interface{} {
120120
}
121121
}
122122

123-
context := map[string]interface{}{
123+
context := map[string]any{
124124
"current": float64(0),
125125
"accumulator": accumulator,
126126
"valueType": valueType,
127127
}
128128

129-
for _, value := range subject.([]interface{}) {
129+
for _, value := range subject.([]any) {
130130
if value == nil {
131131
continue
132132
}

comp.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
// at simulate undefined in javascript
10-
func at(values []interface{}, index int) interface{} {
10+
func at(values []any, index int) any {
1111
if index >= 0 && index < len(values) {
1212
return values[index]
1313
}
@@ -16,7 +16,7 @@ func at(values []interface{}, index int) interface{} {
1616

1717
type undefinedType struct{}
1818

19-
func toNumberForLess(v interface{}) float64 {
19+
func toNumberForLess(v any) float64 {
2020
switch value := v.(type) {
2121
case nil:
2222
return 0
@@ -45,7 +45,7 @@ func toNumberForLess(v interface{}) float64 {
4545

4646
// less reference javascript implementation
4747
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than#description
48-
func less(a, b interface{}) bool {
48+
func less(a, b any) bool {
4949
// If both values are strings, they are compared as strings,
5050
// based on the values of the Unicode code points they contain.
5151
if isString(a) && isString(b) {
@@ -56,7 +56,7 @@ func less(a, b interface{}) bool {
5656
return toNumberForLess(b) > toNumberForLess(a)
5757
}
5858

59-
func hardEquals(a, b interface{}) bool {
59+
func hardEquals(a, b any) bool {
6060
ra := reflect.ValueOf(a).Kind()
6161
rb := reflect.ValueOf(b).Kind()
6262

@@ -67,7 +67,7 @@ func hardEquals(a, b interface{}) bool {
6767
return equals(a, b)
6868
}
6969

70-
func equals(a, b interface{}) bool {
70+
func equals(a, b any) bool {
7171
// comparison to a nil value is falsy
7272
if a == nil || b == nil {
7373
// if a and b is nil, return true, else return falsy

go.mod

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module github.com/diegoholiveira/jsonlogic/v3
22

3-
go 1.14
3+
go 1.18
44

55
require (
66
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df
7-
github.com/stretchr/testify v1.6.1
7+
github.com/stretchr/testify v1.10.0
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v3 v3.0.1 // indirect
814
)

go.sum

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df h1:GSoSVRLoBaFpOOds6QyY1L8AX7uoY+Ln3BHc22W40X0=
22
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM=
3-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
9-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
7+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
8+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
109
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1110
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
13-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

helpers.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import (
55
"strconv"
66
)
77

8-
func is(obj interface{}, kind reflect.Kind) bool {
8+
func is(obj any, kind reflect.Kind) bool {
99
return obj != nil && reflect.TypeOf(obj).Kind() == kind
1010
}
1111

12-
func isBool(obj interface{}) bool {
12+
func isBool(obj any) bool {
1313
return is(obj, reflect.Bool)
1414
}
1515

16-
func isString(obj interface{}) bool {
16+
func isString(obj any) bool {
1717
return is(obj, reflect.String)
1818
}
1919

20-
func isNumber(obj interface{}) bool {
20+
func isNumber(obj any) bool {
2121
switch obj.(type) {
2222
case int, float64:
2323
return true
@@ -26,19 +26,19 @@ func isNumber(obj interface{}) bool {
2626
}
2727
}
2828

29-
func isPrimitive(obj interface{}) bool {
29+
func isPrimitive(obj any) bool {
3030
return isBool(obj) || isString(obj) || isNumber(obj)
3131
}
3232

33-
func isMap(obj interface{}) bool {
33+
func isMap(obj any) bool {
3434
return is(obj, reflect.Map)
3535
}
3636

37-
func isSlice(obj interface{}) bool {
37+
func isSlice(obj any) bool {
3838
return is(obj, reflect.Slice)
3939
}
4040

41-
func isTrue(obj interface{}) bool {
41+
func isTrue(obj any) bool {
4242
if isBool(obj) {
4343
return obj.(bool)
4444
}
@@ -56,8 +56,8 @@ func isTrue(obj interface{}) bool {
5656
return false
5757
}
5858

59-
func toSliceOfNumbers(values interface{}) []float64 {
60-
_values := values.([]interface{})
59+
func toSliceOfNumbers(values any) []float64 {
60+
_values := values.([]any)
6161

6262
numbers := make([]float64, len(_values))
6363
for i, n := range _values {
@@ -66,26 +66,26 @@ func toSliceOfNumbers(values interface{}) []float64 {
6666
return numbers
6767
}
6868

69-
func toNumber(value interface{}) float64 {
69+
func toNumber(value any) float64 {
7070
if isString(value) {
7171
w, _ := strconv.ParseFloat(value.(string), 64)
7272

7373
return w
7474
}
7575

76-
switch value.(type) {
76+
switch value := value.(type) {
7777
case int:
78-
return float64(value.(int))
78+
return float64(value)
7979
default:
8080
return value.(float64)
8181
}
8282
}
8383

84-
func toString(value interface{}) string {
84+
func toString(value any) string {
8585
if isNumber(value) {
86-
switch value.(type) {
86+
switch value := value.(type) {
8787
case int:
88-
return strconv.FormatInt(int64(value.(int)), 10)
88+
return strconv.FormatInt(int64(value), 10)
8989
default:
9090
return strconv.FormatFloat(value.(float64), 'f', -1, 64)
9191
}

internal/testing.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type (
1919
Tests []Test
2020
)
2121

22-
func convertInterfaceToReader(i interface{}) io.Reader {
22+
func convertInterfaceToReader(i any) io.Reader {
2323
var result bytes.Buffer
2424

2525
encoder := json.NewEncoder(&result)
@@ -45,7 +45,7 @@ func GetScenariosFromOfficialTestSuite() Tests {
4545

4646
response.Body.Close()
4747

48-
var scenarios []interface{}
48+
var scenarios []any
4949

5050
err = json.Unmarshal(buffer, &scenarios)
5151
if err != nil {
@@ -55,23 +55,23 @@ func GetScenariosFromOfficialTestSuite() Tests {
5555
}
5656

5757
// add missing but relevant scenarios
58-
var rule []interface{}
58+
var rule []any
5959

6060
scenarios = append(scenarios,
6161
append(rule,
62-
make(map[string]interface{}),
63-
make(map[string]interface{}),
64-
make(map[string]interface{})))
62+
make(map[string]any),
63+
make(map[string]any),
64+
make(map[string]any)))
6565

6666
for _, scenario := range scenarios {
6767
if reflect.ValueOf(scenario).Kind() == reflect.String {
6868
continue
6969
}
7070

7171
tests = append(tests, Test{
72-
Rule: convertInterfaceToReader(scenario.([]interface{})[0]),
73-
Data: convertInterfaceToReader(scenario.([]interface{})[1]),
74-
Expected: convertInterfaceToReader(scenario.([]interface{})[2]),
72+
Rule: convertInterfaceToReader(scenario.([]any)[0]),
73+
Data: convertInterfaceToReader(scenario.([]any)[1]),
74+
Expected: convertInterfaceToReader(scenario.([]any)[2]),
7575
})
7676
}
7777

0 commit comments

Comments
 (0)