Skip to content

Commit

Permalink
Use any instead of interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed Mar 23, 2022
1 parent 51588f1 commit 72cd271
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func (s Schema) Validate(field *Field) (errs Errors) {
}

// Value is a shortcut function used to create a schema for a simple value.
func Value(value interface{}, validator Validator) Schema {
func Value(value any, validator Validator) Schema {
return Schema{
F("", value): validator,
}
}

// Nested is a composite validator factory used to create a validator, which will
// delegate the actual validation to the schema returned by f.
// delegate the actual validation to the validator returned by f.
func Nested[T any](f func(T) Validator) Validator {
return Func(func(field *Field) Errors {
v, ok := field.Value.(T)
Expand All @@ -49,7 +49,7 @@ func Nested[T any](f func(T) Validator) Validator {
}

// Map is a composite validator factory used to create a validator, which will
// do the validation per the key/value schemas associated with a map.
// do the validation per the schemas associated with a map.
func Map[T map[K]V, K comparable, V any](f func(T) map[K]Schema) Validator {
return Func(func(field *Field) (errs Errors) {
v, ok := field.Value.(T)
Expand Down
20 changes: 10 additions & 10 deletions builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func makeErrsMap(errs v.Errors) map[string]v.Error {
func TestNested(t *testing.T) {
cases := []struct {
name string
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestMap(t *testing.T) {

cases := []struct {
name string
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestSlice(t *testing.T) {

cases := []struct {
name string
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestNot(t *testing.T) {
func TestIs(t *testing.T) {
cases := []struct {
name string
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -378,7 +378,7 @@ func TestIs(t *testing.T) {

func TestNonzero(t *testing.T) {
cases := []struct {
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestNonzero(t *testing.T) {

func TestZero(t *testing.T) {
cases := []struct {
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestZero(t *testing.T) {

func TestLenString(t *testing.T) {
cases := []struct {
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -549,7 +549,7 @@ func TestLenString(t *testing.T) {

func TestLenSlice(t *testing.T) {
cases := []struct {
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -601,7 +601,7 @@ func TestLenSlice(t *testing.T) {

func TestRuneCount(t *testing.T) {
cases := []struct {
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func TestIn_Nin(t *testing.T) {
func TestMatch(t *testing.T) {
cases := []struct {
name string
value interface{}
value any
validator v.Validator
errs v.Errors
}{
Expand Down
4 changes: 2 additions & 2 deletions validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package validating
// Field represents a (Name, Value) pair that needs to be validated.
type Field struct {
Name string
Value interface{}
Value any
}

// F is a shortcut for creating a pointer to Field.
func F(name string, value interface{}) *Field {
func F(name string, value any) *Field {
return &Field{Name: name, Value: value}
}

Expand Down

0 comments on commit 72cd271

Please sign in to comment.