1 Star 1 Fork 0

窦雪峰 / go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
jsonData.go 821 Bytes
一键复制 编辑 原始数据 按行查看 历史
窦雪峰 提交于 2021-10-12 12:04 . add response
/*
* @Author: i@douxuefeng.cn
* @Date: 2021-04-16 15:25:14
* @LastEditTime: 2021-10-12 12:03:38
* @LastEditors: i@douxuefeng.cn
* @Description:
* @FilePath: \go-utils\jsonData.go
*/
package go_utils
type JsonData struct {
Code int `json:"code"`
Data interface{} `json:"data"`
Msg string `json:"msg"`
}
func Json(code int, data interface{}, msg string) *JsonData {
return &JsonData{
Code: code,
Data: data,
Msg: msg,
}
}
func JsonNoData(code int, msg string) *JsonData {
return &JsonData{
Code: code,
Msg: msg,
}
}
func JsonErr(code int, err error) *JsonData {
return &JsonData{
Code: code,
Msg: err.Error(),
}
}
func Response(code int, err error, msg string, data interface{}) *JsonData {
if err != nil {
return JsonErr(code, err)
}
return Json(200, data, msg)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/douxuefeng/go-utils.git
git@gitee.com:douxuefeng/go-utils.git
douxuefeng
go-utils
go-utils
v0.1.5

搜索帮助

344bd9b3 5694891 D2dac590 5694891