Unverified Commit ca394fc8 authored by astaxie's avatar astaxie Committed by GitHub

Merge pull request #3182 from GNURub/feature/autobind

Add method to set the data depending on the accepted
parents 9c9ba012 45b68d44
......@@ -275,6 +275,19 @@ func (c *Controller) Redirect(url string, code int) {
c.Ctx.Redirect(code, url)
}
// Set the data depending on the accepted
func (c *Controller) SetData(data interface{}) {
accept := c.Ctx.Input.Header("Accept")
switch accept {
case applicationJSON:
c.Data["json"] = data
case applicationXML, textXML:
c.Data["xml"] = data
default:
c.Data["json"] = data
}
}
// Abort stops controller handler and show the error data if code is defined in ErrorMap or code string.
func (c *Controller) Abort(code string) {
status, err := strconv.Atoi(code)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment