1 Star 0 Fork 0

谭陆颖/record

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
model.go 884 Bytes
一键复制 编辑 原始数据 按行查看 历史
谭陆颖 提交于 2019-12-14 12:07 +08:00 . 完成基本开发,提交开发分支
package model
import "encoding/json"
import "fmt"
// ResResult 用来传递 http 响应的
type ResResult struct {
Ok bool
Msg string
ResultData interface{}
}
// OKData 响应 http 成功
func OKData(data interface{}) []byte {
return toJSONByte(ResResult{
Ok: true,
Msg: "success",
ResultData: data,
})
}
// OKMsg 响应 http 成功
func OKMsg(msg string) []byte {
return toJSONByte(ResResult{
Ok: true,
Msg: msg,
})
}
// OK 响应 http 成功
func OK() []byte {
return toJSONByte(ResResult{
Ok: true,
Msg: "success",
})
}
// Error 服务器发生错误时响应
func Error(msg string) []byte {
return toJSONByte(ResResult{
Ok: false,
Msg: msg,
})
}
// 将响应对象转换为 json 字节
func toJSONByte(r interface{}) []byte {
data, err := json.Marshal(r)
if err != nil {
fmt.Println(err)
}
return data
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tering/record.git
git@gitee.com:tering/record.git
tering
record
record
v0.1.0

搜索帮助