本文整理匯總了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)
}
}
}