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


Golang Error.ListErrors方法代码示例

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


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

示例1: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:28,代码来源:check.go

示例2: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:30,代码来源:check.go

示例3: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:27,代码来源:methods.go

示例4: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:34,代码来源:methods.go

示例5: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:31,代码来源:methods.go

示例6: checkCityCountryNameFormat

func (place *Place) checkCityCountryNameFormat(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	errors := api.Error{}

	if !helpers.IsAConformPlaceName(place.Name) {
		errors.ListErrors = append(errors.ListErrors, "Name of place hasn't a good format")
	} else if !helpers.IsAConformCountry(place.Country) {
		errors.ListErrors = append(errors.ListErrors, "Country of place hasn't a good format")
	} else if !helpers.IsAConformCity(place.City) {
		errors.ListErrors = append(errors.ListErrors, "City of place hasn't a good format")
	}
	if len(errors.ListErrors) > 0 {
		response.WriteHeaderAndEntity(http.StatusUnauthorized, errors)
		helpers.PrintLog(request, response, place.user.Name)
		return
	}
	chain.ProcessFilter(request, response)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:17,代码来源:check.go

示例7: websocketHandler

func websocketHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("In : ")
	user := user.User{}
	user.Token = getParamURI(r.URL.RequestURI(), "token")
	if user.GetUserByToken() == false {
		errors := api.Error{}
		errors.ListErrors = append(errors.ListErrors, "Session doesn't exist")
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusNotAcceptable)
		json.NewEncoder(w).Encode(errors)
		return
	}
	if checkIfUserIsInArray(user.Id) == true {
		errors := api.Error{}
		errors.ListErrors = append(errors.ListErrors, "Websocket session exist.")
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusNotAcceptable)
		json.NewEncoder(w).Encode(errors)
		return
	} else {
		go addUserInArray(user.Id)
	}
	fmt.Println("User :", user.Name)
	socket, _ := upgrader.Upgrade(w, r, nil)
	err := make(chan string)
	run := false
	go pingSocket(socket, err)
	go func() {
		for {
			if run == false {
				go handleChangeNotification(socket, user.Id, err)
				go handleChangeMessage(socket, user.Id, err)
				run = true
			}
			tmp := <-err
			if len(tmp) > 0 {
				fmt.Println("break")
				break
			}
		}
		socket.Close()
		fmt.Println("Out : ")
		removeUserInArray(user.Id)
	}()
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:45,代码来源:websockets.go

示例8: checkContent

func (message *Message) checkContent(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	message.Content = helpers.RemoveManySpaces(request.Request.FormValue("content"))
	if len(message.Content) > 2000 {
		errors := api.Error{}
		errors.ListErrors = append(errors.ListErrors, "a message must be maximum 2000 characters")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, message.user.Name)
		return
	}
	if len(message.Content) == 0 {
		errors := api.Error{}
		errors.ListErrors = append(errors.ListErrors, "you're message is empty")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, message.user.Name)
		return
	}
	chain.ProcessFilter(request, response)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:18,代码来源:check.go

示例9: checkImage

func (message *Message) checkImage(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	errors := api.Error{}
	mpf, _, err := request.Request.FormFile("image")
	if err != nil {
		errors.ListErrors = append(errors.ListErrors, "We were unable to upload your file")
		response.WriteHeaderAndEntity(406, errors)
		helpers.PrintLog(request, response, message.user.Name)
		return
	}
	var buff bytes.Buffer
	fileSize, _ := buff.ReadFrom(mpf)
	if fileSize > 300000 {
		errors.ListErrors = append(errors.ListErrors, "The size of your image is too large")
		response.WriteHeaderAndEntity(406, errors)
		helpers.PrintLog(request, response, message.user.Name)
		return
	}
	chain.ProcessFilter(request, response)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:19,代码来源:check.go

示例10: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:10,代码来源:check.go

示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:10,代码来源:check.go

示例12: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:10,代码来源:check.go

示例13: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:10,代码来源:check.go

示例14: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:10,代码来源:check.go

示例15: 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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:10,代码来源:check.go


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