本文整理汇总了Golang中github.com/robfig/revel.Validation类的典型用法代码示例。如果您正苦于以下问题:Golang Validation类的具体用法?Golang Validation怎么用?Golang Validation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Validation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ValidatePassword
func ValidatePassword(v *revel.Validation, password string) *revel.ValidationResult {
return v.Check(password,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{5},
)
}
示例2: Validate
func (article *Article) Validate(v *revel.Validation) {
v.Check(article.Title,
revel.Required{},
revel.MinSize{1},
revel.MaxSize{256},
)
}
示例3: Validate
func Validate(validation *revel.Validation, obj interface{}) {
// Get reflection data to parse validation tag data
var v reflect.Value = reflect.Indirect(reflect.ValueOf(obj))
// We only want to validate structs and their tagged fields
if v.Kind() != reflect.Struct {
panic(fmt.Sprintf("Object is not a struct. Actual kind is: %s", v.Kind()))
}
// Go through each field in the struct and check for the
// validation tag. Apply appropriate revel check as needed.
t := v.Type()
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
fieldId := fmt.Sprintf("%s.%s", t.Name(), field.Name)
var fieldValidators []revel.Validator
fieldValidators, ok := validationCache[fieldId]
if tag := field.Tag.Get(TagName); !ok && len(tag) > 0 {
fieldValidators = parseTag(tag)
validationCache[fieldId] = fieldValidators
} else if !ok {
fieldValidators = nil
validationCache[fieldId] = nil
}
if len(fieldValidators) > 0 {
validation.Check(v.FieldByName(field.Name).Interface(), fieldValidators...).Key(fieldId)
}
}
}
示例4: Validate
func (r *Restaurant) Validate(v *revel.Validation) {
v.Check(r.Name,
revel.Required{},
revel.MaxSize{150},
revel.MinSize{1},
)
}
示例5: Validate
func (this *Project) Validate(v *r.Validation) {
v.Check(this.Name, r.Required{}, r.MinSize{2}, r.MaxSize{64}, r.Match{projRegex})
if this.DisplayName == "" {
this.DisplayName = this.Name
}
v.Required(this.OwnerId)
}
示例6: ValidatePassword
func (this *User) ValidatePassword(v *r.Validation, password string) {
bin := []byte(_APPSECRET + password + this.Username)
hbin, _ := base64.StdEncoding.DecodeString(this.Password)
err := bcrypt.CompareHashAndPassword(hbin, bin)
if err != nil {
v.Error("密码不匹配")
}
}
示例7: Validate
func (category Category) Validate(v *revel.Validation) {
v.Required(category.Name).Message("请输入名称")
if category.HasName() {
err := &revel.ValidationError{
Message: "名称已存在",
Key: "category.Name",
}
v.Errors = append(v.Errors, err)
}
}
示例8: Validate
func (loginUser *LoginUser) Validate(v *revel.Validation, session *mgo.Session) {
v.Check(loginUser.UserName,
revel.Required{},
revel.Match{USERNAME_REX},
).Message("UserName or password is wrong")
v.Check(loginUser.PasswordStr,
revel.Required{},
revel.Match{PWD_REX},
LegalUserValidator{session, loginUser.UserName},
).Message("UserName or password is wrong")
}
示例9: Validate
func (user *User) Validate(v *revel.Validation) {
v.Check(user.Username,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{4},
revel.Match{userRegex},
)
v.Check(user.Name,
revel.Required{},
revel.MaxSize{100},
)
}
示例10: Validate
func (user *User) Validate(v *revel.Validation) {
v.Check(user.Username,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{3},
revel.Match{userRegex},
).Key("username")
v.Check(user.Password,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{3},
).Key("password")
}
示例11: ValidatePassword
//验证密码
func (P *Password) ValidatePassword(v *revel.Validation) {
v.Required(P.Password).Message("请输入密码!")
v.Required(P.PasswordConfirm).Message("请输入确认密码!")
v.MinSize(P.Password, 6).Message("密码最少六位!")
v.Required(P.Password == P.PasswordConfirm).Message("两次密码不相同!")
}
示例12: Validate
func (menu *Menu) Validate(v *revel.Validation) {
v.Required(menu.Name).Message("请输入菜单名称!")
v.MaxSize(menu.Name, 105).Message("最多35个字")
v.Required(menu.Pid).Message("请选择父菜单!")
v.Required(menu.Url).Message("请输入菜单地址!")
v.Required(menu.Order).Message("请输入排序!")
}
示例13: Validate
func (post *Post) Validate(v *revel.Validation) {
v.Check(
post.Title,
revel.Required{},
revel.MinSize{3},
revel.MaxSize{256},
)
v.Check(
post.Body,
revel.Required{},
revel.MinSize{10},
revel.MaxSize{2048},
)
}
示例14: Validate
func (user *User) Validate(v *revel.Validation) {
v.Check(user.Username,
revel.Required{},
revel.MaxSize{15},
revel.MinSize{4},
revel.Match{userRegex},
)
ValidatePassword(v, user.Password).
Key("user.Password")
v.Check(user.Name,
revel.Required{},
revel.MaxSize{100},
)
}
示例15: Validate
func (category *Category) Validate(v *revel.Validation) {
valid := v.Required(category.Name).Message("请输入名称")
if valid.Ok {
if category.HasName() {
err := &revel.ValidationError{
Message: "该名称已存在",
Key: "category.Name",
}
valid.Error = err
valid.Ok = false
v.Errors = append(v.Errors, err)
}
}
}