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

Golang binding.Errors类代码示例

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

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



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

示例1: validate

func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaron.Locale) binding.Errors {
	if errs.Len() == 0 {
		return errs
	}

	data["HasError"] = true
	AssignForm(f, data)

	typ := reflect.TypeOf(f)
	val := reflect.ValueOf(f)

	if typ.Kind() == reflect.Ptr {
		typ = typ.Elem()
		val = val.Elem()
	}

	for i := 0; i < typ.NumField(); i++ {
		field := typ.Field(i)

		fieldName := field.Tag.Get("form")
		// Allow ignored fields in the struct
		if fieldName == "-" {
			continue
		}

		if errs[0].FieldNames[0] == field.Name {
			data["Err_"+field.Name] = true

			trName := field.Tag.Get("locale")
			if len(trName) == 0 {
				trName = l.Tr("form." + field.Name)
			} else {
				trName = l.Tr(trName)
			}

			switch errs[0].Classification {
			case binding.ERR_REQUIRED:
				data["ErrorMsg"] = trName + l.Tr("form.require_error")
			case binding.ERR_ALPHA_DASH:
				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error")
			case binding.ERR_ALPHA_DASH_DOT:
				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
			case binding.ERR_SIZE:
				data["ErrorMsg"] = trName + l.Tr("form.size_error", GetSize(field))
			case binding.ERR_MIN_SIZE:
				data["ErrorMsg"] = trName + l.Tr("form.min_size_error", GetMinSize(field))
			case binding.ERR_MAX_SIZE:
				data["ErrorMsg"] = trName + l.Tr("form.max_size_error", GetMaxSize(field))
			case binding.ERR_EMAIL:
				data["ErrorMsg"] = trName + l.Tr("form.email_error")
			case binding.ERR_URL:
				data["ErrorMsg"] = trName + l.Tr("form.url_error")
			default:
				data["ErrorMsg"] = l.Tr("form.unknown_error") + " " + errs[0].Classification
			}
			return errs
		}
	}
	return errs
}
开发者ID:pecastro,项目名称:gogs,代码行数:60,代码来源:auth.go


示例2: validate

func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaron.Locale) binding.Errors {
	if errs.Len() == 0 {
		return errs
	}

	data["HasError"] = true
	AssignForm(f, data)

	typ := reflect.TypeOf(f)
	val := reflect.ValueOf(f)

	if typ.Kind() == reflect.Ptr {
		typ = typ.Elem()
		val = val.Elem()
	}

	for i := 0; i < typ.NumField(); i++ {
		field := typ.Field(i)

		fieldName := field.Tag.Get("form")
		// Allow ignored fields in the struct
		if fieldName == "-" {
			continue
		}

		if errs[0].FieldNames[0] == field.Name {
			data["Err_"+field.Name] = true
			trName := l.Tr("form." + field.Name)
			switch errs[0].Classification {
			case binding.RequiredError:
				data["ErrorMsg"] = trName + l.Tr("form.require_error")
			case binding.AlphaDashError:
				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error")
			case binding.AlphaDashDotError:
				data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
			case binding.MinSizeError:
				data["ErrorMsg"] = trName + l.Tr("form.min_size_error", GetMinSize(field))
			case binding.MaxSizeError:
				data["ErrorMsg"] = trName + l.Tr("form.max_size_error", GetMaxSize(field))
			case binding.EmailError:
				data["ErrorMsg"] = trName + l.Tr("form.email_error")
			case binding.UrlError:
				data["ErrorMsg"] = trName + l.Tr("form.url_error")
			default:
				data["ErrorMsg"] = l.Tr("form.unknown_error") + " " + errs[0].Classification
			}
			return errs
		}
	}
	return errs
}
开发者ID:ericcapricorn,项目名称:gogs,代码行数:51,代码来源:auth.go


示例3: LoginPost

func LoginPost(loginform form.LoginForm, ctx *middleware.Context, sess session.Store, errs binding.Errors) {
	if ctx.IsSigned {
		ctx.Redirect("/")
		return
	}
	if errs.Len() > 0 {
		ctx.Data["errors"] = errs
		ctx.HTML(200, "user/login")
		return
	}
	loginform.Login(sess)
	ctx.Redirect("/")
	return
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:14,代码来源:user.go


示例4: validateApiReq

func validateApiReq(errs binding.Errors, data map[string]interface{}, f auth.Form) binding.Errors {
	if errs.Len() == 0 {
		return errs
	}

	data["HasError"] = true

	typ := reflect.TypeOf(f)
	val := reflect.ValueOf(f)

	if typ.Kind() == reflect.Ptr {
		typ = typ.Elem()
		val = val.Elem()
	}

	for i := 0; i < typ.NumField(); i++ {
		field := typ.Field(i)

		fieldName := field.Tag.Get("form")
		// Allow ignored fields in the struct
		if fieldName == "-" {
			continue
		}

		if errs[0].FieldNames[0] == field.Name {
			switch errs[0].Classification {
			case binding.ERR_REQUIRED:
				data["ErrorMsg"] = fieldName + " cannot be empty"
			case binding.ERR_ALPHA_DASH:
				data["ErrorMsg"] = fieldName + " must be valid alpha or numeric or dash(-_) characters"
			case binding.ERR_ALPHA_DASH_DOT:
				data["ErrorMsg"] = fieldName + " must be valid alpha or numeric or dash(-_) or dot characters"
			case binding.ERR_MIN_SIZE:
				data["ErrorMsg"] = fieldName + " must contain at least " + auth.GetMinSize(field) + " characters"
			case binding.ERR_MAX_SIZE:
				data["ErrorMsg"] = fieldName + " must contain at most " + auth.GetMaxSize(field) + " characters"
			case binding.ERR_EMAIL:
				data["ErrorMsg"] = fieldName + " is not a valid e-mail address"
			case binding.ERR_URL:
				data["ErrorMsg"] = fieldName + " is not a valid URL"
			default:
				data["ErrorMsg"] = "Unknown error: " + errs[0].Classification
			}
			return errs
		}
	}
	return errs
}
开发者ID:noikiy,项目名称:gogs,代码行数:48,代码来源:miscellaneous.go


示例5: JudgeScore

func JudgeScore(ctx *middleware.Context, errs binding.Errors, scorform form.ScoreForm) {
	if errs.Len() > 0 {
		ctx.Data["errors"] = errs
		ctx.HTML(200, "project/score")
		return
	}

	// group, err := ctx.User.GroupSpecifcProject(ctx.Project)
	// if err != nil {
	// 	ctx.Data["error"] = "目前只支持小组长登陆"
	// 	ctx.HTML(200, "project/detail")
	// 	return
	// }
	scorform.UpdateScore(ctx)
	ctx.Data["success"] = "评分成功"
	ctx.HTML(200, "project/score")
	// ctx.Redirect("/")
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:18,代码来源:score.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang cache.Cacher函数代码示例发布时间:2022-05-23
下一篇:
Golang mlog.GetLogger函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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