本文整理匯總了Golang中github.com/microcosm-cc/microcosm/models.Context.RespondWithLocation方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithLocation方法的具體用法?Golang Context.RespondWithLocation怎麽用?Golang Context.RespondWithLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/microcosm-cc/microcosm/models.Context
的用法示例。
在下文中一共展示了Context.RespondWithLocation方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Read
// Read handles GET
func (ctl *CommentContextController) Read(c *models.Context) {
_, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
// Start Authorisation
perms := models.GetPermission(
models.MakeAuthorisationContext(
c, 0, itemTypeID, itemID),
)
if !perms.CanRead {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
// End Authorisation
limit, _, status, err := h.GetLimitAndOffset(c.Request.URL.Query())
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
m, status, err := models.GetCommentSummary(c.Site.ID, itemID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
link, status, err := m.GetPageLink(limit, c.Auth.ProfileID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
pageURL, err := url.Parse(link.Href)
if err != nil {
c.RespondWithErrorMessage(err.Error(), http.StatusInternalServerError)
return
}
queryString := pageURL.Query()
queryString.Add("comment_id", strconv.FormatInt(m.ID, 10))
pageURL.RawQuery = queryString.Encode()
c.RespondWithLocation(pageURL.String())
}
示例2: Read
// Read handles GET
func (ctl *RedirectController) Read(c *models.Context) {
redirect, status, err := redirector.GetRedirect(c.RouteVars["short_url"])
if err != nil {
if status == http.StatusNotFound {
c.RespondWithErrorMessage(
fmt.Sprintf("%v", err.Error()),
http.StatusNotFound,
)
return
}
c.RespondWithErrorMessage(
fmt.Sprintf("Could not retrieve redirect: %v", err.Error()),
http.StatusInternalServerError,
)
return
}
c.RespondWithLocation(redirect.URL)
}
示例3: Read
// Read handles GET
func (ctl *LastCommentController) Read(c *models.Context) {
itemType, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
perms := models.GetPermission(models.MakeAuthorisationContext(c, 0, itemTypeID, itemID))
if !perms.CanRead {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
parsed := c.Request.URL
query := parsed.Query()
limit, _, status, err := h.GetLimitAndOffset(query)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
query.Del("limit")
if limit != h.DefaultQueryLimit {
query.Set("limit", strconv.FormatInt(limit, 10))
}
lastComment, status, err := models.GetLastComment(itemTypeID, itemID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
location := fmt.Sprintf(
"%s/%d",
h.ItemTypesToAPIItem[itemType],
itemID,
)
parsed.Path = location
// Construct location of the last comment on the item.
if lastComment.Valid {
_, _, offset, _, err := models.GetPageNumber(
lastComment.ID,
limit,
c.Auth.ProfileID,
)
if err != nil {
query.Del("offset")
if offset != h.DefaultQueryOffset {
query.Set("offset", strconv.FormatInt(offset, 10))
}
query.Del("comment_id")
query.Set("comment_id", strconv.FormatInt(lastComment.ID, 10))
parsed.RawQuery = query.Encode()
c.RespondWithLocation(parsed.String())
return
}
}
parsed.RawQuery = query.Encode()
c.RespondWithLocation(parsed.String())
}