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

Golang binding.Errors类代码示例

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

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



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

示例1: Validate

// Validate the RegisterModel instance
func (vm RegisterViewModel) Validate(errors binding.Errors, req *http.Request) binding.Errors {
	vm.Account.Name = strings.TrimSpace(vm.Account.Name)
	vm.Account.ContactName = strings.TrimSpace(vm.Account.ContactName)
	vm.Account.ContactEmail = strings.TrimSpace(vm.Account.ContactEmail)
	vm.Account.ContactPhoneNumber = strings.TrimSpace(vm.Account.ContactPhoneNumber)
	vm.Account.Host = strings.TrimSpace(vm.Account.Host)

	if len(vm.Account.Host) > 20 {
		errors.Add([]string{"host"}, "", "The host must be smaller than 20 characters")
	}

	if len(vm.Account.Name) < 3 || len(vm.Account.Name) > 100 {
		errors.Add([]string{"name"}, "", "The account name must be at least 3 characters or smaller than 255")
	}

	if len(vm.Account.ContactName) < 3 {
		errors.Add([]string{"contact_name"}, "", "The contact name must be at least 3 characters or smaller than 255")
	}

	if len(vm.Account.ContactPhoneNumber) < 10 || len(vm.Account.ContactPhoneNumber) > 50 {
		errors.Add([]string{"contact_phone_number"}, "", "A valid phone number must be provided")
	}

	_, err := mail.ParseAddress(vm.Account.ContactEmail)
	if len(vm.Account.ContactEmail) < 3 || err != nil {
		errors.Add([]string{"email"}, "", "A valid email address must be provided")
	}

	return errors
}
开发者ID:masom,项目名称:doorbot,代码行数:31,代码来源:accounts.go


示例2: adminErrorHandler

func adminErrorHandler(err binding.Errors, w http.ResponseWriter) {
	if err.Len() > 0 {
		e := err[0]
		s := e.Classification + ": "
		if len(e.FieldNames) > 0 {
			s += strings.Join(e.FieldNames, ",")
		}
		s += " " + e.Message
		writeResponse(w, errors.NewError(errors.JsonError, s))
	}
}
开发者ID:shevilangle,项目名称:sports,代码行数:11,代码来源:common.go


示例3: CreateBlog

func CreateBlog(r render.Render, err binding.Errors, post models.Post, data middleware.Data) {
	if err.Count() > 0 {
		data["errors"] = err
		r.HTML(200, "blogs/new", data)
		return
	}
	if e := models.CreateNewPost(&post); e != nil {
		log.Println(err)
	}
	r.Redirect("/")
}
开发者ID:jijeshmohan,项目名称:martini-spike,代码行数:11,代码来源:blogs.go


示例4: ErrorHandler

func ErrorHandler(err binding.Errors, request *http.Request, resp http.ResponseWriter) {
	if err.Len() > 0 {
		e := err[0]
		s := e.Classification + ": "
		if len(e.FieldNames) > 0 {
			s += strings.Join(e.FieldNames, ",")
		}
		s += " " + e.Message
		writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.JsonError, s))
	}
}
开发者ID:shevilangle,项目名称:sports,代码行数:11,代码来源:common.go


示例5: CreateDevice

func CreateDevice(r render.Render, err binding.Errors, device models.Device, data middleware.Data, req *http.Request) {
	if err.Len() > 0 {
		data["errors"] = err
		r.HTML(http.StatusBadRequest, "devices/new", data)
		return
	}
	if e := models.AddDevice(&device); e != nil {
		data["errors"] = updateError(err, e)
		r.HTML(http.StatusBadRequest, "devices/new", data)
		return
	}
	websocketClient(req.Host, device)
	r.Redirect("/devices")
}
开发者ID:jijeshmohan,项目名称:mtgrid,代码行数:14,代码来源:devices.go


示例6: createAppEvents

func (srv *httpServer) createAppEvents(evt Event, err binding.Errors, resp http.ResponseWriter, req *http.Request) string {
	if err.Count() > 0 {
		resp.WriteHeader(http.StatusBadRequest)
		return fmt.Sprintf(`{"errors":"%v"}`, err)
	}
	socketID := req.URL.Query().Get("socket_id")
	log.Printf("received event: %#v\n", evt)
	for _, payload := range evt.Payloads(socketID) {
		_, pubErr := srv.h.PublishEvent(payload)
		if pubErr != nil {
			log.Printf("ERROR: %v\n", pubErr)
			resp.WriteHeader(http.StatusInternalServerError)
			return `{}`
		}
	}
	resp.WriteHeader(http.StatusAccepted)
	return `{}`
}
开发者ID:henrikhodne,项目名称:hustle,代码行数:18,代码来源:http_server.go


示例7: AccountSave

// AccountSave renders user's account page
func AccountSave(r render.Render, tokens oauth2.Tokens, session sessions.Session, username UsernameForm, err binding.Errors) {
	pd := NewPageData(tokens, session)

	if len(username.Username) > 0 {
		existingUser := &User{Username: username.Username}
		db.Where(existingUser).First(existingUser)

		if existingUser.ID > 0 {
			err.Add([]string{"username"}, "RequiredError", "This username is already taken.")
		}

		log.Printf("[AccountSave] existing user: %s", existingUser)
	}

	if err.Len() == 0 {
		user := pd.User
		if user.Username != username.Username {
			path := filepath.Join(HomeDir(), "app/public/files/"+user.Username)
			if len(user.Username) == 0 {
				path = filepath.Join(HomeDir(), "app/public/files/"+username.Username)
			}
			if _, err := os.Stat(path); os.IsNotExist(err) || len(user.Username) == 0 {
				os.Mkdir(path, 0755)
			}
			if _, err := os.Stat(path); err == nil {
				newPath := filepath.Join(HomeDir(), "app/public/files/"+username.Username)
				os.Rename(path, newPath)
			}
			user.Username = username.Username
			db.Save(user)
		}
		session.AddFlash("You have successfully updated your BareCV username / domain.", "success")
		r.Redirect(config.AppUrl+"/account", 302)
	} else {
		pd.Errors = &err
		log.Printf("[AccountSave] errors: %s", err[0].Classification)
		r.HTML(200, "account", pd)
	}
}
开发者ID:tpiha,项目名称:barecv,代码行数:40,代码来源:views.go


示例8: Save

// Save saves dashboard page
func Save(r render.Render, tokens oauth2.Tokens, session sessions.Session, profile ProfileForm, err binding.Errors) {
	pd := NewPageData(tokens, session)

	log.Printf("[Save] profile: %s", profile)

	if err.Len() == 0 {
		user := pd.User
		user.Name = profile.Name
		user.Profession = profile.Profession
		user.Email = profile.Email
		user.Phone = profile.Phone
		user.Website = profile.Website
		user.Address = profile.Address
		db.Save(user)
		session.AddFlash("You have successfully updated your BareCV profile.", "success")
		r.Redirect(config.AppUrl+"/cv", 302)
	} else {
		pd.Errors = &err
		log.Printf("[Save] errors: %s", err[0].FieldNames)
		r.HTML(200, "cv", pd)
	}
}
开发者ID:tpiha,项目名称:barecv,代码行数:23,代码来源:views.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang cors.Allow函数代码示例发布时间:2022-05-23
下一篇:
Golang binding.Json函数代码示例发布时间: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