controller.go 897 字节
package controllers

import (
	"github.com/beego/beego/v2/server/web/context"
	"github.com/linmadan/egglib-go/web/beego"
	"github.com/linmadan/egglib-go/web/beego/utils"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
)

func ResponseGrid(c beego.BaseController, data interface{}, err error) {
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(c.Ctx, err)
	} else {
		response = ResponseGridData(c.Ctx, data)
	}
	c.Data["json"] = response
	c.ServeJSON()
}

func ResponseGridData(ctx *context.Context, data interface{}) utils.JsonResponse {
	jsonResponse := utils.JsonResponse{}
	jsonResponse["code"] = 0
	jsonResponse["msg"] = "ok"
	jsonResponse["data"] = map[string]interface{}{"grid": data}
	ctx.Input.SetData("outputData", jsonResponse)
	return jsonResponse
}

func Must(err error) {
	if err != nil {
		log.Logger.Error(err.Error())
	}
}