当前位置: 首页>>代码示例>>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;未经允许,请勿转载。