-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run `gotip test -gcflags=-G=3 example_simple_value_test.go`.
- Loading branch information
1 parent
b98ec44
commit 21aa3a7
Showing
4 changed files
with
39 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/RussellLuo/validating/v2 | ||
|
||
go 1.14 | ||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
package validating | ||
|
||
// Field represents a (Name, ValuePtr) pair need to be validated. | ||
type Field struct { | ||
Name string | ||
ValuePtr interface{} | ||
// Field represents a (Name, Value) pair that needs to be validated. | ||
type Field[T any] struct { | ||
Name string | ||
Value T | ||
} | ||
|
||
// F is a shortcut for creating an instance of Field. | ||
func F(name string, valuePtr interface{}) Field { | ||
return Field{name, valuePtr} | ||
func F[T any](name string, value T) *Field[T] { | ||
return &Field[T]{name, value} | ||
} | ||
|
||
// Validator is an interface for representing a validating's validator. | ||
type Validator interface { | ||
Validate(field Field) Errors | ||
type Validator[T any] interface { | ||
Validate(field *Field[T]) Errors | ||
} | ||
|
||
// Validate invokes v.Validate with an empty field. | ||
func Validate(v Validator) (errs Errors) { | ||
return v.Validate(Field{}) | ||
func Validate[T any](v Validator[T]) (errs Errors) { | ||
return v.Validate(&Field[T]{}) | ||
} |