package utils import ( "github.com/beego/beego/v2/server/web" ) // Response 统一 JSON 结构体 type Response struct { Code int `json:"code"` Msg string `json:"msg"` Data interface{} `json:"data"` } // JSON 统一返回处理 func JSON(c *web.Controller, code int, msg string, data interface{}) { c.Data["json"] = Response{ Code: code, Msg: msg, Data: data, } c.ServeJSON() c.StopRun() // 类似 PHP 的 exit() }