123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package controllers
- import (
- "github.com/astaxie/beego"
- "hongze/hongze_mobile_admin/utils"
- "rdluck_tools/log"
- )
- var apiLog *log.Log
- func init() {
- if utils.RunMode == "release" {
- logDir := `/data/rdlucklog/hongze_api`
- apiLog = log.Init("20060102.api", logDir)
- } else {
- apiLog = log.Init("20060102.api")
- }
- }
- type BaseCommon struct {
- beego.Controller
- Response
- }
- type Response struct {
- Code int `json:"code"`
- Data interface{} `json:"data"`
- Msg string `json:"msg"`
- ErrMsg string `json:"errMsg";description:"给开发工程师看的错误信息"`
- }
- const (
- SUCCESS = 200
- ERROR = 400
- TOKEN_ERROR = 401
- BIND_ERROR = 403
- SIGN_ERROR = 3
- )
- func (this BaseCommon) Result() {
- this.Controller.Data["json"] = this.Response
- this.Controller.ServeJSON()
- this.StopRun()
- }
- func (this BaseCommon) Ok() {
- this.Response.Code = SUCCESS
- this.Response.Msg = "操作成功"
- this.Response.Data = map[string]interface{}{}
- this.Result()
- }
- func (this BaseCommon) OkWithMessage(message string) {
- this.Response.Code = SUCCESS
- this.Response.Msg = message
- this.Response.Data = map[string]interface{}{}
- this.Result()
- }
- func (this BaseCommon) OkWithData(data interface{}) {
- this.Response.Code = SUCCESS
- this.Response.Msg = "操作成功"
- this.Response.Data = data
- this.Result()
- }
- func (this BaseCommon) OkDetailed(data interface{}, message string) {
- this.Response.Code = SUCCESS
- this.Response.Msg = message
- this.Response.Data = data
- this.Result()
- }
- func (this BaseCommon) Fail() {
- this.Response.Code = ERROR
- this.Response.Msg = "操作失败"
- this.Response.Data = map[string]interface{}{}
- this.Result()
- }
- func (this BaseCommon) FailWithMessage(message, errMessage string) {
- this.Response.Code = ERROR
- this.Response.Msg = message
- this.Response.ErrMsg = errMessage
- this.Response.Data = map[string]interface{}{}
- this.Result()
- }
- func (this BaseCommon) TokenError(data interface{}, message string) {
- this.Response.Code = TOKEN_ERROR
- this.Response.Msg = message
- this.Response.Data = data
- this.Result()
- }
- func (this BaseCommon) TokenMsgError(message, errMessage string) {
- this.Response.Code = TOKEN_ERROR
- this.Response.Msg = message
- this.Response.ErrMsg = errMessage
-
- this.Result()
- }
- func (this BaseCommon) BindError(data interface{}, message string) {
- this.Response.Code = BIND_ERROR
- this.Response.Msg = message
- this.Response.Data = data
- this.Result()
- }
- func (this BaseCommon) BindMsgError(message, errMessage string) {
- this.Response.Code = BIND_ERROR
- this.Response.Msg = message
- this.Response.ErrMsg = errMessage
-
- this.Result()
- }
- func (this BaseCommon) SignError(message string) {
- this.Response.Code = SIGN_ERROR
- this.Response.Msg = message
- this.Response.Data = map[string]interface{}{}
- this.Result()
- }
- func (this BaseCommon) FailWithDetailed(code int, data interface{}, message string) {
- this.Response.Code = code
- this.Response.Msg = message
- this.Response.Data = data
- this.Result()
- }
|