Changelog History
-
v2.2.0 Changes
November 30, 2020๐ Changed structure for module version
commit b12bd3f
-
v2.1.0 Changes
November 30, 2020Loyalty on show field name
If there is JSON tag on struct the gody will get the field name from json tag value
Example where struct has a JSON tag
type Response struct { FirstName string `validate:"not_empty" json:"fname"`}resp := Response{}if validated, err := validator.Validate(resp); err != nil { ...}// output error: field fname cannot be empty
Example where struct hasn't a JSON tag
type Response struct { FirstName string
validate:"not_empty"
}resp := Response{}if validated, err := validator.Validate(resp); err != nil { ...}// output error: field firstName cannot be empty
issue #13
-
v2.0.0 Changes
April 14, 2020Validator struct
Validate more clean for source code
validator := gody.NewValidator()if validated, err := validator.Validate(/*struct*/); err != nil { ... }
On demand rules
...if err := validator.AddRules(/*...rules*/); err != nil { ... } ...
๐ Support for set a custom tag name
...if err := validator.SetTagName(/*name*/); err != nil { ... } ...
๐ Raw functions support
RawSerialize receive tag name and the struct to validate.
func RawSerialize(tn string, b interface{}) ([]Field, error)
RawValidate receive the struct to validate, tag name and custom rules.
func RawValidate(b interface{}, tn string, rules []Rule) (bool, error)
0๏ธโฃ RawDefaultValidate receive the struct to validate, tag name and custom rules.
func RawDefaultValidate(b interface{}, tn string, rules []Rule) (bool, error)
๐ฑ > ๐
DefaultValidate
andRawDefaultValidate
it's same, both uses as default rules built-in gody.โ Remove the necessity for tag in struct and slice validation
issue #9
-
v1.1.0 Changes
April 01, 2020๐ Support rule parameter
- Boolean rule (Any parameter will be a boolean value if it isn't setted) - Issue #6
โ ๏ธ In case of custom rules , it'll receive a empty string in parameter value. The rule will decide if it's a either value boolean (
true
orfalse
) or any other type value.type User struct { Name string `validate:"not\_empty"`Ageint`validate:"is\_adult"` // A custom rule} ...// Validate handle for is\_adult rulefunc Validate(field, value, parameter string) (bool, error) { fmt.Println(field) // Field name from struct fmt.Println(value) // Value of field from struct fmt.Println(parameter) // Value setted in tag validate for rule, it's a empty string// TODO: Validation for adult agereturn true, nil} ...
๐ Support rules
๐ฑ ๐ It's a boolean rule, whatever if it receive some parameter value as boolean or any other.
-
v1.0.0 Changes
February 08, 2020๐ Support validations
- Shallow validate (Validation on first layer from struct)
- Deep validate (Validation on behind of first layers from struct)
- Slice validate (Validation with slice or array in any level from struct)
๐ Support rules
- Required (Verified if the field got some value)
- Enum (Verified the field if given some default values the got value is equals which one)
- Min (Verified if the field got some value higher that given parameter)
- Max (Verified if the field got some value less that given parameter)
- Min bound (Verified if the field got some string length higher that given parameter)
- Max bound (Verified if the field got some string length less that given parameter)
๐ Support custom rules to validate