当前位置: 首页>>代码示例>>Golang>>正文


Golang BindingErrors.Count方法代码示例

本文整理汇总了Golang中github.com/gogits/gogs/modules/base.BindingErrors.Count方法的典型用法代码示例。如果您正苦于以下问题:Golang BindingErrors.Count方法的具体用法?Golang BindingErrors.Count怎么用?Golang BindingErrors.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gogits/gogs/modules/base.BindingErrors的用法示例。


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

示例1: ErrorHandler

// ErrorHandler simply counts the number of errors in the
// context and, if more than 0, writes a 400 Bad Request
// response and a JSON payload describing the errors with
// the "Content-Type" set to "application/json".
// Middleware remaining on the stack will not even see the request
// if, by this point, there are any errors.
// This is a "default" handler, of sorts, and you are
// welcome to use your own instead. The Bind middleware
// invokes this automatically for convenience.
func ErrorHandler(errs base.BindingErrors, resp http.ResponseWriter) {
	if errs.Count() > 0 {
		resp.Header().Set("Content-Type", "application/json; charset=utf-8")
		if _, ok := errs.Overall[base.BindingDeserializationError]; ok {
			resp.WriteHeader(http.StatusBadRequest)
		} else {
			resp.WriteHeader(422)
		}
		errOutput, _ := json.Marshal(errs)
		resp.Write(errOutput)
		return
	}
}
开发者ID:Julianzz,项目名称:gogs,代码行数:22,代码来源:binding.go

示例2: Validate

func (f *UpdateProfileForm) Validate(errors *base.BindingErrors, req *http.Request, context martini.Context) {
	if req.Method == "GET" || errors.Count() == 0 {
		return
	}

	data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
	data["HasError"] = true

	if len(errors.Overall) > 0 {
		for _, err := range errors.Overall {
			log.Error("UpdateProfileForm.Validate: %v", err)
		}
		return
	}

	validate(errors, data, f)
}
开发者ID:Julianzz,项目名称:gogs,代码行数:17,代码来源:user.go

示例3: Validate

func (f *AddSSHKeyForm) Validate(errors *base.BindingErrors, req *http.Request, context martini.Context) {
	data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
	AssignForm(f, data)

	if req.Method == "GET" || errors.Count() == 0 {
		if req.Method == "POST" &&
			(len(f.KeyContent) < 100 || !strings.HasPrefix(f.KeyContent, "ssh-rsa")) {
			data["HasError"] = true
			data["ErrorMsg"] = "SSH key content is not valid"
		}
		return
	}

	data["HasError"] = true
	if len(errors.Overall) > 0 {
		for _, err := range errors.Overall {
			log.Error("AddSSHKeyForm.Validate: %v", err)
		}
		return
	}

	validate(errors, data, f)
}
开发者ID:Julianzz,项目名称:gogs,代码行数:23,代码来源:setting.go


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