7
type ExampleQueryInput struct {
Cid int `v:"required#cid can not be empty"`
}
GetStruct 反射创建Stuct时会为其生成0值
if elem.Kind() == reflect.Ptr {
if !elem.IsValid() || elem.IsNil() {
e := reflect.New(elem.Type().Elem()).Elem()
elem.Set(e.Addr())
elem = e
} else {
...
}
导致CheckStruct比较时 不能区分int类型是传入的0,还是int默认的0值
if required {
return !(value == "")
} else {
return true
}
value会为"0"