govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

add more than one filter in struct defination

Open zhangmingkai4315 opened this issue 5 years ago • 2 comments

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 avatar May 28 '19 01:05 zhangmingkai4315

@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)
}

TuringZhu avatar Jul 18 '19 04:07 TuringZhu

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.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev