當前位置: 首頁>>代碼示例>>Golang>>正文


Golang revel.Validation類代碼示例

本文整理匯總了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},
	)
}
開發者ID:huaguzi,項目名稱:revel,代碼行數:7,代碼來源:user.go

示例2: Validate

func (article *Article) Validate(v *revel.Validation) {
	v.Check(article.Title,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{256},
	)
}
開發者ID:stunti,項目名稱:bloggo,代碼行數:7,代碼來源:article.go

示例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)
		}
	}
}
開發者ID:shmifaats,項目名稱:rvlvalidate,代碼行數:29,代碼來源:rvlvalidate.go

示例4: Validate

func (r *Restaurant) Validate(v *revel.Validation) {
	v.Check(r.Name,
		revel.Required{},
		revel.MaxSize{150},
		revel.MinSize{1},
	)
}
開發者ID:jtescher,項目名稱:publichealthapi,代碼行數:7,代碼來源:restaurant.go

示例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)
}
開發者ID:pa001024,項目名稱:MoeFeed,代碼行數:7,代碼來源:Project.go

示例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("密碼不匹配")
	}
}
開發者ID:pa001024,項目名稱:MoeFeed,代碼行數:8,代碼來源:User.go

示例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)
	}
}
開發者ID:zeuson,項目名稱:gorevel,代碼行數:11,代碼來源:category.go

示例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")
}
開發者ID:jsli,項目名稱:cms,代碼行數:12,代碼來源:login_user.go

示例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},
	)
}
開發者ID:netsharec,項目名稱:ironzebra,代碼行數:13,代碼來源:user.go

示例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")
}
開發者ID:BYVoid,項目名稱:byvnotes,代碼行數:13,代碼來源:user.go

示例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("兩次密碼不相同!")
}
開發者ID:qmdx,項目名稱:GoCMS,代碼行數:8,代碼來源:admin.go

示例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("請輸入排序!")
}
開發者ID:qmdx,項目名稱:GoCMS,代碼行數:7,代碼來源:menu.go

示例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},
	)
}
開發者ID:puredevotion,項目名稱:jobs,代碼行數:15,代碼來源:post.go

示例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},
	)
}
開發者ID:huaguzi,項目名稱:revel,代碼行數:16,代碼來源:user.go

示例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)
		}
	}
}
開發者ID:jsli,項目名稱:gorevel,代碼行數:16,代碼來源:category.go


注:本文中的github.com/robfig/revel.Validation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。