Skip to content

Commit d29ab7b

Browse files
committed
feat: Upgrading to a more recent version of golang, any over interface
1 parent 6f0703a commit d29ab7b

File tree

19 files changed

+54
-48
lines changed

19 files changed

+54
-48
lines changed

absent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type absentRule struct {
2525
}
2626

2727
// Validate checks if the given value is valid or not.
28-
func (r absentRule) Validate(value interface{}) error {
28+
func (r absentRule) Validate(value any) error {
2929
if r.condition {
3030
value, isNil := Indirect(value)
3131
if !r.skipNil && !isNil || r.skipNil && !isNil && !IsEmpty(value) {

date.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r DateRule) Max(max time.Time) DateRule {
7979
}
8080

8181
// Validate checks if the given value is a valid date.
82-
func (r DateRule) Validate(value interface{}) error {
82+
func (r DateRule) Validate(value any) error {
8383
value, isNil := Indirect(value)
8484
if isNil || IsEmpty(value) {
8585
return nil

each.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ type EachRule struct {
2626
}
2727

2828
// Validate loops through the given iterable and calls the Ozzo Validate() method for each value.
29-
func (r EachRule) Validate(value interface{}) error {
30-
return r.ValidateWithContext(nil, value)
29+
func (r EachRule) Validate(value any) error {
30+
return r.ValidateWithContext(context.TODO(), value)
3131
}
3232

3333
// ValidateWithContext loops through the given iterable and calls the Ozzo ValidateWithContext() method for each value.
34-
func (r EachRule) ValidateWithContext(ctx context.Context, value interface{}) error {
34+
func (r EachRule) ValidateWithContext(ctx context.Context, value any) error {
3535
errs := Errors{}
3636

3737
v := reflect.ValueOf(value)

error.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ type (
2020
Code() string
2121
Message() string
2222
SetMessage(string) Error
23-
Params() map[string]interface{}
24-
SetParams(map[string]interface{}) Error
23+
Params() map[string]any
24+
SetParams(map[string]any) Error
2525
}
2626

2727
// ErrorObject is the default validation error
2828
// that implements the Error interface.
2929
ErrorObject struct {
3030
code string
3131
message string
32-
params map[string]interface{}
32+
params map[string]any
3333
}
3434

3535
// Errors represents the validation errors that are indexed by struct field names, map or slice keys.
@@ -69,23 +69,23 @@ func (e ErrorObject) Code() string {
6969
}
7070

7171
// SetParams set the error's params.
72-
func (e ErrorObject) SetParams(params map[string]interface{}) Error {
72+
func (e ErrorObject) SetParams(params map[string]any) Error {
7373
e.params = params
7474
return e
7575
}
7676

7777
// AddParam add parameter to the error's parameters.
78-
func (e ErrorObject) AddParam(name string, value interface{}) Error {
78+
func (e ErrorObject) AddParam(name string, value any) Error {
7979
if e.params == nil {
80-
e.params = make(map[string]interface{})
80+
e.params = make(map[string]any)
8181
}
8282

8383
e.params[name] = value
8484
return e
8585
}
8686

8787
// Params returns the error's params.
88-
func (e ErrorObject) Params() map[string]interface{} {
88+
func (e ErrorObject) Params() map[string]any {
8989
return e.params
9090
}
9191

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module github.com/monetr/validation
22

3-
go 1.13
3+
go 1.22
44

55
require (
66
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496
77
github.com/stretchr/testify v1.4.0
88
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.0 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v2 v2.2.2 // indirect
14+
)

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
44
github.com/davecgh/go-spew v1.1.0/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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
87
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
98
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
109
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

in.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var ErrInInvalid = NewError("validation_in_invalid", "must be a valid value")
1515
// reflect.DeepEqual() will be used to determine if two values are equal.
1616
// For more details please refer to https://golang.org/pkg/reflect/#DeepEqual
1717
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
18-
func In(values ...interface{}) InRule {
18+
func In(values ...any) InRule {
1919
return InRule{
2020
elements: values,
2121
err: ErrInInvalid,
@@ -24,12 +24,12 @@ func In(values ...interface{}) InRule {
2424

2525
// InRule is a validation rule that validates if a value can be found in the given list of values.
2626
type InRule struct {
27-
elements []interface{}
27+
elements []any
2828
err Error
2929
}
3030

3131
// Validate checks if the given value is valid or not.
32-
func (r InRule) Validate(value interface{}) error {
32+
func (r InRule) Validate(value any) error {
3333
value, isNil := Indirect(value)
3434
if isNil || IsEmpty(value) {
3535
return nil

is/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func isDomain(value string) bool {
275275

276276
func isUTFNumeric(value string) bool {
277277
for _, c := range value {
278-
if unicode.IsNumber(c) == false {
278+
if !unicode.IsNumber(c) {
279279
return false
280280
}
281281
}

length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type LengthRule struct {
5050
}
5151

5252
// Validate checks if the given value is valid or not.
53-
func (r LengthRule) Validate(value interface{}) error {
53+
func (r LengthRule) Validate(value any) error {
5454
value, isNil := Indirect(value)
5555
if isNil || IsEmpty(value) {
5656
return nil
@@ -100,5 +100,5 @@ func buildLengthRuleError(min, max int) (err Error) {
100100
err = ErrLengthEmptyRequired
101101
}
102102

103-
return err.SetParams(map[string]interface{}{"min": min, "max": max})
103+
return err.SetParams(map[string]any{"min": min, "max": max})
104104
}

match.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type MatchRule struct {
2828
}
2929

3030
// Validate checks if the given value is valid or not.
31-
func (r MatchRule) Validate(value interface{}) error {
31+
func (r MatchRule) Validate(value any) error {
3232
value, isNil := Indirect(value)
3333
if isNil {
3434
return nil

0 commit comments

Comments
 (0)