1 Star 0 Fork 0

Gitee Go / core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ui.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
Gitee 提交于 2021-08-31 17:37 . 1.0 release.
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)
}
}
1
https://gitee.com/gitee-go/core.git
git@gitee.com:gitee-go/core.git
gitee-go
core
core
main

搜索帮助