package controllers import ( "IC/enums" _ "IC/service" "github.com/astaxie/beego" ) type BaseAPIController struct { beego.Controller } // func (this *BaseAPIController) Prepare() { // this.BaseController.Prepare() // beego.Trace("============================================================") // beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID")) // beego.Trace("session : %v", this.GetSession("info")) // this.SetSession("info", time.Now().Format("2006/01/02 15:04:05")) // beego.Trace("============================================================") // } // 输出数据格式化 /* success json: { "state": 1, "code": 0, "data": json, } fail json: { "state": 0, "code": int, "msg": string, } */ func (this *BaseAPIController) ServeSuccessJSON(data map[string]interface{}) { this.Data["json"] = enums.MakeSuccessResponseJSON(data) this.ServeJSON() } func (this *BaseAPIController) ServeFailJSONWithSGJErrorCode(code int) { this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(code) this.ServeJSON() } func (this *BaseAPIController) ServeFailJSONWithSGJError(err *enums.SGJError) { this.Data["json"] = enums.MakeFailResponseJSONWithSGJError(err) this.ServeJSON() } func (this *BaseAPIController) ServeFailJsonSend(code int, msg string) { this.Data["json"] = enums.MakeFailResponseJSON(msg, code) this.ServeJSON() }