We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
列如用户表单中,用户名称和密码最小是需要6位的 Username string orm:"unique;size(32)" form:"Username" valid:"Required;MaxSize(20);MinSize(6)" Password string orm:"size(32)" form:"Password" valid:"Required;MaxSize(20);MinSize(6)"
orm:"unique;size(32)" form:"Username" valid:"Required;MaxSize(20);MinSize(6)"
orm:"size(32)" form:"Password" valid:"Required;MaxSize(20);MinSize(6)"
我测试时表单数据验证不起作用,比如输入jack,密码两次输入都不一样就可以新建用户成功了。 然后阅读源码修改UserModel.go的checkUser函数中 b, _ := valid.Valid(&u) 为 b, _ := valid.Valid(u) 或者b, _ := valid.Valid(*u) ,即可以正常表单数据验证,修改如下 //验证用户信息 func checkUser(u *User) (err error) { valid := validation.Validation{} b, _ := valid.Valid(u)//此处将取地址符合去掉了,表单数据验证就有效 if !b { for _, err := range valid.Errors { log.Println(err.Key, err.Message) return errors.New(err.Message) } } return nil }
以我个人理解应该是传入是指针,指针已经指向了地址,所以无需再取地址了。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
列如用户表单中,用户名称和密码最小是需要6位的
Username string
orm:"unique;size(32)" form:"Username" valid:"Required;MaxSize(20);MinSize(6)"
Password string
orm:"size(32)" form:"Password" valid:"Required;MaxSize(20);MinSize(6)"
我测试时表单数据验证不起作用,比如输入jack,密码两次输入都不一样就可以新建用户成功了。
然后阅读源码修改UserModel.go的checkUser函数中 b, _ := valid.Valid(&u) 为 b, _ := valid.Valid(u) 或者b, _ := valid.Valid(*u) ,即可以正常表单数据验证,修改如下
//验证用户信息
func checkUser(u *User) (err error) {
valid := validation.Validation{}
b, _ := valid.Valid(u)//此处将取地址符合去掉了,表单数据验证就有效
if !b {
for _, err := range valid.Errors {
log.Println(err.Key, err.Message)
return errors.New(err.Message)
}
}
return nil
}
以我个人理解应该是传入是指针,指针已经指向了地址,所以无需再取地址了。
The text was updated successfully, but these errors were encountered: