當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。