govalidator
govalidator copied to clipboard
add more than one filter in struct defination
i have a custom struct define like below, is that possible for server field valid success for ip or domain
import (
"github.com/asaskevich/govalidator"
)
func main() {
type Conn struct {
Server string `valid:"ip,domain,required"`
}
conn := Conn{Server: "127.0.0.1"}
result, err := govalidator.ValidateStruct(conn)
if err != nil {
println("error: " + err.Error())
}
println(result)
}
Expect :
true
Result Output
error: Server: The following validator is invalid or can't be applied to the field: "domain"
false
same like only the last validate is valid and the ip valid is ignored.
@zhangmingkai4315 I think domain
is not a valid tag for govalidator
the following code can run success
import (
"github.com/asaskevich/govalidator"
)
func main() {
type Conn struct {
Server string `valid:"ip,required"`
}
conn := Conn{Server: "127.0.0.1"}
result, err := govalidator.ValidateStruct(conn)
if err != nil {
println("error: " + err.Error())
}
println(result)
}
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.