當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Errors.Len方法代碼示例

本文整理匯總了Golang中github.com/martini-contrib/binding.Errors.Len方法的典型用法代碼示例。如果您正苦於以下問題:Golang Errors.Len方法的具體用法?Golang Errors.Len怎麽用?Golang Errors.Len使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/martini-contrib/binding.Errors的用法示例。


在下文中一共展示了Errors.Len方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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.Len方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。