代码拉取完成,页面将自动刷新
package core
import (
"fmt"
"gitee.com/gitee-go/core/common"
"github.com/gin-gonic/gin"
"net/http"
)
type UIRes struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
msgs []interface{}
lc string
status int
}
func NewUIRes(code int) *UIRes {
return &UIRes{Code: code}
}
func NewUIResOk(data ...interface{}) *UIRes {
c := &UIRes{Code: common.UICodeOk}
if len(data) > 0 {
c.Data = data[0]
}
return c
}
func (c *UIRes) SetCode(code int) *UIRes {
c.Code = code
return c
}
func (c *UIRes) SetStatus(a int) *UIRes {
c.status = a
return c
}
func (c *UIRes) SetMsgf(format string, args ...interface{}) *UIRes {
c.Msg = fmt.Sprintf(format, args...)
return c
}
func (c *UIRes) SetLc(lc string) *UIRes {
c.lc = lc
return c
}
func (c *UIRes) SetMsgObjs(args ...interface{}) *UIRes {
c.msgs = append(c.msgs, args...)
return c
}
func (c *UIRes) SetData(data interface{}) *UIRes {
c.Data = data
return c
}
func (c *UIRes) ResJson(g *gin.Context, format ...bool) {
if c.Msg == "" {
if c.lc == "" {
c.lc = "zh" //默认
}
c.Msg = common.GetUIMsg(c.lc, c.Code, c.msgs...)
}
stat := http.StatusOK
if c.status != 0 {
stat = c.status
}
if len(format) > 0 && format[0] {
g.IndentedJSON(stat, c)
} else {
g.JSON(stat, c)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。