Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-it_IT-translation
- Loading branch information
Showing
56 changed files
with
10,640 additions
and
1,462 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
* @go-playground/validator-maintainers |
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Maintainers Guide | ||
|
||
### Semantic Versioning | ||
Semantic versioning as defined [here](https://semver.org) must be strictly adhered to. | ||
|
||
### External Dependencies | ||
Any new external dependencies MUST: | ||
- Have a compatible LICENSE present. | ||
- Be actively maintained. | ||
- Be approved by @go-playground/admins | ||
|
||
### PR Merge Requirements | ||
- Up-to-date branch. | ||
- Passing tests and linting. | ||
- CODEOWNERS approval. | ||
- Tests that cover both the Happy and Unhappy paths. |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-playground/validator/v10" | ||
) | ||
|
||
var validate *validator.Validate | ||
|
||
func main() { | ||
validate = validator.New() | ||
|
||
validateMap() | ||
validateNestedMap() | ||
} | ||
|
||
func validateMap() { | ||
user := map[string]interface{}{"name": "Arshiya Kiani", "email": "zytel3301@gmail.com"} | ||
|
||
// Every rule will be applied to the item of the data that the offset of rule is pointing to. | ||
// So if you have a field "email": "omitempty,required,email", the validator will apply these | ||
// rules to offset of email in user data | ||
rules := map[string]interface{}{"name": "required,min=8,max=32", "email": "omitempty,required,email"} | ||
|
||
// ValidateMap will return map[string]error. | ||
// The offset of every item in errs is the name of invalid field and the value | ||
// is the message of error. If there was no error, ValidateMap method will | ||
// return an EMPTY map of errors, not nil. If you want to check that | ||
// if there was an error or not, you must check the length of the return value | ||
errs := validate.ValidateMap(user, rules) | ||
|
||
if len(errs) > 0 { | ||
fmt.Println(errs) | ||
// The user is invalid | ||
} | ||
|
||
// The user is valid | ||
} | ||
|
||
func validateNestedMap() { | ||
|
||
data := map[string]interface{}{ | ||
"name": "Arshiya Kiani", | ||
"email": "zytel3301@gmail.com", | ||
"details": map[string]interface{}{ | ||
"family_members": map[string]interface{}{ | ||
"father_name": "Micheal", | ||
"mother_name": "Hannah", | ||
}, | ||
"salary": "1000", | ||
}, | ||
} | ||
|
||
// Rules must be set as the structure as the data itself. If you want to dive into the | ||
// map, just declare its rules as a map | ||
rules := map[string]interface{}{ | ||
"name": "min=4,max=32", | ||
"email": "required,email", | ||
"details": map[string]interface{}{ | ||
"family_members": map[string]interface{}{ | ||
"father_name": "required,min=4,max=32", | ||
"mother_name": "required,min=4,max=32", | ||
}, | ||
"salary": "number", | ||
}, | ||
} | ||
|
||
if len(validate.ValidateMap(data, rules)) == 0 { | ||
// Data is valid | ||
} | ||
|
||
// Data is invalid | ||
} |
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
Oops, something went wrong.