本文整理匯總了Golang中github.com/microcosm-cc/microcosm/models.Context.RespondWithError方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithError方法的具體用法?Golang Context.RespondWithError怎麽用?Golang Context.RespondWithError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/microcosm-cc/microcosm/models.Context
的用法示例。
在下文中一共展示了Context.RespondWithError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Read
// Read handles GET
func (ctl *Redirect404Controller) Read(c *models.Context) {
// Just call this with authentication (if you have it) and pass in the
// unknown URL as a GET param:
//
// https://dev1.microco.sm/api/v1/resolve?url=http%3A%2F%2Fwww.lfgss.com%2Fforumdisplay.php%3Ff%3D1
//
// The URL in the GET param should be URL encoded to ensure that if it has
// any querystring, nothing goes awry. An example querystring URL might be:
//
// http://www.lfgss.com/private.php?t=7865&page=32
//
// If you don't get a page/offset back from this, then you haven't URL encoded
// it.
u := c.Request.URL
q := u.Query()
inURL := q.Get("url")
if inURL == "" {
c.RespondWithError(http.StatusBadRequest)
return
}
c.RespondWithData(resolver.Resolve(c.Site.ID, inURL, c.Auth.ProfileID))
}