asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.02k stars 556 forks source link

BUG? Validation work only for one struct field (see sample) #304

Open gvem opened 6 years ago

gvem commented 6 years ago

// I`m try to validate struct, but validation work only for Shortcut field with no errors. // It is a bug? // ================= package main

import ( "fmt"

"github.com/asaskevich/govalidator"

)

func main() { type stRequest_Application_Create struct { Title string d:"Application title for human reading" valid: "alphanum~Field Title must be alphanumeric, required~Field Title is empty" Shortcut string d:"Custom short alias for the Application title" valid:"alphanum~Field Shortcut must be alphanumeric, required~Field Shortcut is empty" Enabled bool d:"Application state" valid: "-" }

post := &stRequest_Application_Create{"", "asasas", true}

res, err := govalidator.ValidateStruct(post)

if !res {
    fmt.Printf("Error: %s, %#v \n", err.Error(), post)
}

}

arsoba commented 6 years ago

@gvem try to delete spaces between valid: and validation rules. valid: "alphanum~Field Title must be alphanumeric, required~Field Title is empty" to valid:"alphanum~Field Title must be alphanumeric, required~Field Title is empty"

sergeyglazyrindev commented 2 years ago

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.