本文整理匯總了Golang中github.com/microcosm-cc/microcosm/models.Context.RespondWithStatus方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithStatus方法的具體用法?Golang Context.RespondWithStatus怎麽用?Golang Context.RespondWithStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/microcosm-cc/microcosm/models.Context
的用法示例。
在下文中一共展示了Context.RespondWithStatus方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Read
func (wc *WhoAmIController) Read(c *models.Context) {
if c.Request.Method != "GET" {
c.RespondWithNotImplemented()
return
}
if c.Auth.UserID < 0 {
c.RespondWithErrorMessage(
"Bad access token supplied",
http.StatusForbidden,
)
return
}
if c.Auth.UserID == 0 {
c.RespondWithErrorMessage(
"You must be authenticated to ask 'who am I?'",
http.StatusForbidden,
)
return
}
m, status, err := models.GetProfileSummary(c.Site.ID, c.Auth.ProfileID)
if err != nil {
if status == http.StatusNotFound {
c.RespondWithErrorMessage(
"You must create a user profile for this site at api/v1/profiles/",
http.StatusNotFound,
)
return
}
c.RespondWithErrorMessage(
fmt.Sprintf("Could not retrieve profile: %v", err.Error()),
http.StatusInternalServerError,
)
return
}
location := fmt.Sprintf(
"%s/%d",
h.APITypeProfile,
m.ID,
)
if c.Auth.ProfileID > 0 && c.Auth.Method == "query" {
u, _ := url.Parse(location)
qs := u.Query()
qs.Del("access_token")
qs.Add("access_token", c.Auth.AccessToken.TokenValue)
u.RawQuery = qs.Encode()
location = u.String()
}
c.ResponseWriter.Header().Set("Location", location)
c.RespondWithStatus(307)
}