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


Golang Context.IsAborted方法代碼示例

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


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

示例1: Error

func Error(c *gin.Context) {
	c.Next()
	id, _ := c.Get("request_id")

	// Log out every error we have encoutered (which in most cases is just 1)
	for _, ginError := range c.Errors {
		actError := ginError.Err
		log.InfoFields("Request error", log.Fields{
			"request_id": id,
			"body":       formatErrorBody(actError.Error()),
		})
	}

	// Grab the last error and use that as the error we return to the client
	if len(c.Errors) > 0 {
		clientError := c.Errors[len(c.Errors)-1].Err

		// If it isn't an errors.Http type, assume it is a 500 and return that
		switch clientError.(type) {
		case errors.Http:
			break
		default:
			if c.IsAborted() {
				clientError = errors.NewHttp(c.Writer.Status(), formatErrorBody(clientError.Error()))
			} else {
				clientError = errors.NewHttp(http.StatusInternalServerError, "Unrecognized error")
			}
		}

		// Now write the error to the client
		c.JSON(clientError.(errors.Http).Code, clientError)
	}

}
開發者ID:notion-app,項目名稱:api,代碼行數:34,代碼來源:mw_error.go

示例2: Update

// PATCH /repos/:repo_id/reviews/:review_id
func (r *reviews) Update(c *gin.Context) {
	type updateParams struct {
		Smell      string `json:"smell"`
		Status     string `json:"status"`
		AssignedTo uint   `json:"assigned_to"`
	}

	var params updateParams
	review := c.MustGet("review").(model.Review)
	db := database.GetDB()

	if c.Bind(&params) == nil {
		updates := model.Review{}

		if params.Smell != "" {
			var smell model.Smell
			if err := db.Where("name = ?", params.Smell).Find(&smell).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, errors.New("Invalid smell"))
			}

			updates.SmellId = smell.ID
		}
		if params.Status != "" {
			var status model.Status
			if err := db.Where("name = ?", params.Status).Find(&status).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, errors.New("Invalid status"))
			}

			updates.StatusId = status.ID
		}
		if params.AssignedTo > 0 {
			updates.AssignedToId = params.AssignedTo
		}

		if c.IsAborted() {
			return
		} else if updates.SmellId == 0 && updates.StatusId == 0 && updates.AssignedToId == 0 {
			c.String(http.StatusNotModified, "")
		} else {
			if err := db.Model(&review).Updates(updates).Error; err != nil {
				c.AbortWithError(http.StatusInternalServerError, err)
			} else {
				c.String(http.StatusNoContent, "")
			}
		}
	}
}
開發者ID:pazjacket,項目名稱:Leko-_-revy-api,代碼行數:48,代碼來源:reviews.go

示例3: Create

// POST /repos/:repo_id/reviews
func (r *reviews) Create(c *gin.Context) {
	var params createParam
	user := c.MustGet("user").(model.User)
	repo := c.MustGet("repo").(model.Repository)
	db := database.GetDB()

	if c.Bind(&params) == nil {
		review := model.Review{}

		if params.Smell == "" {
			params.Smell = smellDefault
		}

		var smell model.Smell
		var status model.Status

		review.RepositoryId = repo.ID
		review.CreatedById = user.ID
		review.Sha = params.Sha
		review.File = params.File
		review.Line = params.Line
		review.AssignedToId = params.AssignedToId
		if err := db.Where("name = ?", params.Smell).Find(&smell).Error; err != nil {
			c.AbortWithError(http.StatusBadRequest, errors.New("Invalid smell"))
		} else {
			review.SmellId = smell.ID
			review.Smell = smell
		}

		if err := db.Where("name = ?", statusDefault).Find(&status).Error; err != nil {
			c.AbortWithError(http.StatusBadRequest, errors.New("Invalid status"))
		} else {
			review.StatusId = status.ID
			review.Status = status
		}

		if c.IsAborted() {
			return
		}
		if err := db.Create(&review).Error; err != nil {
			c.AbortWithError(http.StatusInternalServerError, err)
		} else {
			c.JSON(http.StatusCreated, review)
		}
	}
}
開發者ID:pazjacket,項目名稱:Leko-_-revy-api,代碼行數:47,代碼來源:reviews.go

示例4: List

// GET /repos/:repo_id/reviews
func (r *reviews) List(c *gin.Context) {
	var reviews []model.Review
	var query queryParam
	repo := c.MustGet("repo").(model.Repository)
	db := database.GetDB()

	if c.Bind(&query) == nil {
		if query.Limit > limitMax {
			c.AbortWithError(http.StatusBadRequest, errors.New("limit should be less than "+strconv.Itoa(limitMax)))
		}

		q := db.Where(&model.Review{RepositoryId: repo.ID}).Preload("Smell").Preload("Status")

		if query.Limit > 0 {
			q = q.Limit(query.Limit)
		}
		if query.SinceId > 0 {
			q = q.Where("reviews.id >= ?", query.SinceId)
		}
		if query.Smell != "" {
			var smell model.Smell
			if err := db.Where("name = ?", query.Smell).Find(&smell).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, errors.New("Invalid smell"))
			}

			q = q.Where("smell_id = ?", smell.ID)
		}
		if query.Status != "" {
			var status model.Status
			if err := db.Where("name = ?", query.Status).Find(&status).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, errors.New("Invalid status"))
			}

			q = q.Where("status_id = ?", status.ID)
		}

		if c.IsAborted() {
			return
		}
		if err := q.Find(&reviews).Error; err != nil {
			c.AbortWithError(http.StatusInternalServerError, err)
		} else {
			c.JSON(http.StatusOK, reviews)
		}
	}
}
開發者ID:pazjacket,項目名稱:Leko-_-revy-api,代碼行數:47,代碼來源:reviews.go

示例5: CreateAndGet

// CreateAndGet creates a presence and get presences on current topic
func (m *PresencesController) CreateAndGet(ctx *gin.Context) {
	m.create(ctx)
	if ctx.IsAborted() {
		return
	}

	fiften := strconv.FormatInt(time.Now().Unix()-15, 10)

	topicIn, _ := GetParam(ctx, "topic") // no error possible here
	criteria := &models.PresenceCriteria{
		Skip:            0,
		Limit:           1000,
		Topic:           topicIn,
		DateMinPresence: fiften,
	}

	m.listWithCriteria(ctx, criteria)
}
開發者ID:vmalguy,項目名稱:tat,代碼行數:19,代碼來源:presences.go


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