本文整理汇总了Golang中SpottedRethink/api.Error类的典型用法代码示例。如果您正苦于以下问题:Golang Error类的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Error类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: acceptPlace
func (place *Place) acceptPlace(request *restful.Request, response *restful.Response) {
if place.getGeolocation() == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "We were unable to geolocate your plate")
response.WriteHeaderAndEntity(500, errors)
return
}
place.ValidatedAt = time.Now()
place.Validated = true
_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
go func() {
notif := notification.SetPlaceAccepted()
notif.UserId = place.UserId
notif.UserIdFrom = place.user.Id
notif.IdThing = place.Id
notif.Name = place.Name
notif.IdLink = place.Id
notif.CreateNotification()
}()
response.WriteHeaderAndEntity(http.StatusOK, place)
helpers.PrintLog(request, response, place.user.Name)
}
示例2: handleImage
func (place *Place) handleImage(request *restful.Request, response *restful.Response) {
errors := api.Error{}
request.Request.ParseMultipartForm(32 << 20)
mpf, hdr, _ := request.Request.FormFile("image")
ext := filepath.Ext(hdr.Filename)
if helpers.CheckFileExtension(ext) == false {
errors.ListErrors = append(errors.ListErrors, "Only .jpg, .jpeg or .png are authorized.")
response.WriteHeaderAndEntity(406, errors)
return
}
if strings.Compare(place.Image, "") != 0 {
helpers.RemoveFile("./assets/Images/" + place.Image)
}
place.Image = helpers.GenerateHash(50) + ext
go helpers.PutFile("assets/Images/"+place.Image, mpf)
_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
response.WriteHeaderAndEntity(http.StatusOK, place)
helpers.PrintLog(request, response, place.user.Name)
}
示例3: checkDate
func (place *Place) checkDate(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if place.Type != "event" {
chain.ProcessFilter(request, response)
return
}
if place.Type == "event" && place.Recurring == true {
chain.ProcessFilter(request, response)
return
}
errors := api.Error{}
inOneMonth := time.Now().AddDate(0, 1, 0)
lastOneMonth := time.Now().AddDate(0, -1, 0)
if place.StartAt.After(place.EndAt) {
errors.ListErrors = append(errors.ListErrors, "start date of an event can't be less than end date")
} else if place.StartAt.After(inOneMonth) {
errors.ListErrors = append(errors.ListErrors, "start date can not be in more than a month in the future")
} else if place.EndAt.Before(lastOneMonth) {
errors.ListErrors = append(errors.ListErrors, "")
}
if len(errors.ListErrors) > 0 {
response.WriteHeaderAndEntity(http.StatusUnauthorized, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例4: checkBodyCreate
func (user *User) checkBodyCreate(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
private := UserCreate{}
errors := api.Error{}
err := request.ReadEntity(&private)
if err != nil {
response.AddHeader("Content-Type", "text/plain")
response.WriteErrorString(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, user.Name)
return
}
user.Email = strings.TrimSpace(private.Email)
user.Name = helpers.RemoveManySpaces(helpers.MakeFirstUpperCase(strings.ToLower(private.Name)))
if user.isTwoPasswordAreIdentical(private.Password, private.Password2) == false {
errors.ListErrors = append(errors.ListErrors, "Two passwords aren't identical")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, user.Name)
return
}
if len(private.Password) < 6 {
errors.ListErrors = append(errors.ListErrors, "Your password must contain at least 6 characters")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, user.Name)
return
}
user.Password = private.Password
chain.ProcessFilter(request, response)
}
示例5: createPlace
func (place *Place) createPlace(request *restful.Request, response *restful.Response) {
place.Lat = 0
place.Lng = 0
place.PostNb = 0
place.ValidatedAt = *new(time.Time)
place.Validated = false
place.CreateAt = time.Now()
place.UserId = place.user.Id
place.Id = *new(string)
request.Request.ParseMultipartForm(32 << 20)
mpf, hdr, _ := request.Request.FormFile("image")
ext := filepath.Ext(hdr.Filename)
if helpers.CheckFileExtension(ext) == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "Only .jpg, .jpeg or .png are authorized.")
response.WriteHeaderAndEntity(406, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
place.Image = helpers.GenerateHash(50) + ext
go helpers.PutFile("assets/Images/"+place.Image, mpf)
resp, err := r.Table("places").Insert(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
place.Id = resp.GeneratedKeys[0]
response.WriteHeaderAndEntity(http.StatusCreated, place)
helpers.PrintLog(request, response, place.user.Name)
}
示例6: checkType
func (place *Place) checkType(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
errors := api.Error{}
if place.Type != "event" && place.Type != "place" {
errors.ListErrors = append(errors.ListErrors, "Type doesn't exist")
response.WriteHeaderAndEntity(http.StatusUnauthorized, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例7: CheckIfPlaceIsValidated
func (place *Place) CheckIfPlaceIsValidated(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if place.Validated == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "This spotted isn't validated, you cannot do this action on it.")
response.WriteHeaderAndEntity(http.StatusUnauthorized, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例8: checkIfUserIsMatchRecipient
func (match *Match) checkIfUserIsMatchRecipient(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if match.user.Id != match.UserIdY {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "you must be match's recipient to accept it")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, match.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例9: CheckIfPostIsValidated
func (post *Post) CheckIfPostIsValidated(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if post.Validated == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "This post hasn't been accepted, you cannot have this action on it.")
response.WriteHeaderAndEntity(http.StatusNotFound, errors)
helpers.PrintLog(request, response, post.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例10: checkIfLikeBelongsUser
func (like *Like) checkIfLikeBelongsUser(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if like.UserId != like.user.Id {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "This like is not yours")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, like.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例11: checkIfMatchIsAccepted
func (match *Match) checkIfMatchIsAccepted(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if match.Validated == true {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "this match is already validated")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, match.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例12: checkUserIsInTalk
func (talk *Talk) checkUserIsInTalk(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if talk.user.Id != talk.UserIdX && talk.user.Id != talk.UserIdY {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "This talk doesn't exist.")
response.WriteHeaderAndEntity(http.StatusNotFound, errors)
helpers.PrintLog(request, response, talk.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例13: checkIfNameExist
func (place *Place) checkIfNameExist(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if place.getPlaceByName() == true {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "A place or an event related to this name already exists")
response.WriteHeaderAndEntity(http.StatusUnauthorized, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例14: CheckAndGetPostById
func (post *Post) CheckAndGetPostById(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
post.Id = request.PathParameter("post-id")
if post.GetPostById() == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "This post doesn't exist.")
response.WriteHeaderAndEntity(http.StatusNotFound, errors)
helpers.PrintLog(request, response, post.user.Name)
return
}
chain.ProcessFilter(request, response)
}
示例15: CheckIfAPostIsPendingInPlace
func (post *Post) CheckIfAPostIsPendingInPlace(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if post.countUsersPendingPostsInPlace() == 1 && post.user.Group < 100 {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "An event request to add a post in this spotted is already pending.")
response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
helpers.PrintLog(request, response, post.user.Name)
return
}
chain.ProcessFilter(request, response)
}