package controllers import ( "github.com/astaxie/beego" ) type JsonBasicResponse struct { Status int Message string } const JSON_ERROR int = 400 const JSON_INT_ERROR int = 500 const JSON_SUCCESS int = 200 // BaseController operations for BaseController type BaseController struct { beego.Controller } func (c *BaseController) ServeJsonError(message string) { json := JsonBasicResponse{JSON_ERROR, message} c.Data["json"] = &json ///c.Ctx.ResponseWriter.WriteHeader(400) c.ServeJSON() } func (c *BaseController) ServeJsonErrorWithCode(errorcode int, message string) { json := JsonBasicResponse{errorcode, message} c.Data["json"] = &json c.ServeJSON() } func (c *BaseController) ServeJsonSuccess(message string) { json := JsonBasicResponse{JSON_SUCCESS, message} c.Data["json"] = &json c.ServeJSON() }