Skip to content

Releases: guiferpa/gody

v2.2.0

30 Nov 21:49
Compare
Choose a tag to compare

Changed structure for module version

commit b12bd3f

v2.1.0

30 Nov 21:24
75cfbf6
Compare
Choose a tag to compare

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

14 Apr 18:28
Compare
Choose a tag to compare

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 and RawDefaultValidate 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

01 Apr 17:37
6fd8753
Compare
Choose a tag to compare

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 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

  • NotEmpty (Verified if the field got some value) - Issue #7

📓 It's a boolean rule, whatever if it receive some parameter value as boolean or any other.

v1.0.0

08 Feb 17:36
Compare
Choose a tag to compare

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