multitenantStack/controllers/base.go

39 lines
822 B
Go
Raw Normal View History

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