Releases: guiferpa/gody
Releases · guiferpa/gody
v2.2.0
v2.1.0
Loyalty 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
Validator 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)
- 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
Support rule parameter
- Boolean rule (Any parameter will be a boolean value if it isn't setted) - Issue #6
true
or false
) or any other type value.
type User struct {
Name string `validate:"not_empty"`
Age int `validate:"is_adult"` // A custom rule
}
...
// Validate handle for is_adult rule
func 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 age
return true, nil
}
...
Support rules
📓 It's a boolean rule, whatever if it receive some parameter value as boolean or any other.
v1.0.0
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)