multitenantStack/controllers/base.go

48 lines
1.1 KiB
Go
Raw Normal View History

2018-11-07 10:10:51 +00:00
package controllers
import (
"github.com/astaxie/beego"
)
// JSONBasicResponse The minimal JSON response
type JSONBasicResponse struct {
2018-11-07 10:10:51 +00:00
Status int
Message string
}
// JSONError code for a input error
const JSONError int = 400
// JSONInternalError code for an internal error
const JSONInternalError int = 500
// JSONSuccess code for a success
const JSONSuccess int = 200
2018-11-07 10:10:51 +00:00
// BaseController operations for BaseController
type BaseController struct {
beego.Controller
}
// ServeJSONError respond with a JSON error
func (c *BaseController) ServeJSONError(message string) {
json := JSONBasicResponse{JSONError, 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
}
// ServeJSONErrorWithCode respond with a JSON error and specify code
func (c *BaseController) ServeJSONErrorWithCode(errorcode int, message string) {
json := JSONBasicResponse{errorcode, message}
2018-11-07 15:27:39 +00:00
c.Data["json"] = &json
c.ServeJSON()
}
// ServeJSONSuccess respond with a JSON success message
func (c *BaseController) ServeJSONSuccess(message string) {
json := JSONBasicResponse{JSONSuccess, message}
2018-11-07 15:27:39 +00:00
c.Data["json"] = &json
c.ServeJSON()
2018-11-07 10:10:51 +00:00
}