• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang revel.Validation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/robfig/revel.Validation的典型用法代码示例。如果您正苦于以下问题:Golang Validation类的具体用法?Golang Validation怎么用?Golang Validation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Validation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Validate

func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Password)
	//v.MinSize(user.Password, 6)
	v.Required(user.Email)
	v.Email(user.Email)

	if user.Email == "[email protected]" && user.Password == "test" {
		user.Id = "6964943e-535a-4736-85ad-4baaa9656709"
	} else {
		v.Error("Sorry! invalid account ...")
	}
}
开发者ID:puspesh,项目名称:cdfs,代码行数:12,代码来源:user.go


示例17: checkImageExt

func checkImageExt(v *revel.Validation, file *multipart.File, header *multipart.FileHeader, formField string) bool {
	if !strings.Contains(IMAGE_EXTS, strings.ToLower(path.Ext(header.Filename))) {
		err := &revel.ValidationError{
			Message: "只能上传图片",
			Key:     formField,
		}
		v.Errors = append(v.Errors, err)
		return false
	}

	if (*file).(Sizer).Size() > IMAGE_LIMIT_SIZE {
		err := &revel.ValidationError{
			Message: fmt.Sprintf("图片尺寸不超过%dKB", IMAGE_LIMIT_SIZE),
			Key:     formField,
		}
		v.Errors = append(v.Errors, err)
		return false
	}

	return true
}
开发者ID:zeuson,项目名称:gorevel,代码行数:21,代码来源:application.go


示例18: checkFileExt

func checkFileExt(v *revel.Validation, header *multipart.FileHeader, fileExts, formField, message string) bool {
	if !strings.Contains(fileExts, strings.ToLower(path.Ext(header.Filename))) {
		err := &revel.ValidationError{
			Message: message,
			Key:     formField,
		}
		v.Errors = append(v.Errors, err)
		return false
	}

	return true
}
开发者ID:zeuson,项目名称:gorevel,代码行数:12,代码来源:application.go


示例19: Validate

func (topic Topic) Validate(v *revel.Validation) {
	v.Required(topic.Title).Message("请输入标题")
	if utf8.RuneCountInString(topic.Title) > 35 {
		err := &revel.ValidationError{
			Message: "最多35个字",
			Key:     "topic.Title",
		}
		v.Errors = append(v.Errors, err)
	}
	v.Required(topic.Category).Message("请选择分类")
	v.Required(topic.Content).Message("帖子内容不能为空")
}
开发者ID:zeuson,项目名称:gorevel,代码行数:12,代码来源:topic.go


示例20: ValidateCreate

func (user *User) ValidateCreate(v *revel.Validation) {
	validators.UniqueUsername(v, user.Username).Key("user.Username")
	validators.UniqueEmail(v, user.Email).Key("user.Email")

	v.Required(user.Password)
	v.Required(user.PasswordConfirm)

	v.Required(user.PasswordConfirm == user.Password).Message("Passwords must match")
}
开发者ID:Qwait,项目名称:revauth,代码行数:9,代码来源:user.go



注:本文中的github.com/robfig/revel.Validation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.Booking类代码示例发布时间:2022-05-28
下一篇:
Golang revel.Response类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap