1 Star 1 Fork 0

007lz / go-tinyid

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
resp.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
lizhen 提交于 2023-10-30 15:35 . 代码框架搭建
package response
import (
"net/http"
"github.com/gin-gonic/gin"
"gitee.com/git-lz/go-tinyid/common/merrors"
)
type Response struct {
Errno int `json:"code"`
Msg string `json:"message"`
Data interface{} `json:"data"`
IsSucc bool `json:"is_succ"`
}
func NewResponse() *Response {
return &Response{
IsSucc: true,
}
}
func (r *Response) WithDefaultMsg(errno int) *Response {
tx := r
msg, ok := merrors.ErnoMsgMap[errno]
if !ok {
msg = "unknown error"
}
if errno != merrors.ErnoSuccess {
tx.IsSucc = false
}
tx.Msg = msg
tx.Errno = errno
return tx
}
func (r *Response) WithMsg(errno int, msg string) *Response {
tx := r
if errno != merrors.ErnoSuccess {
tx.IsSucc = false
}
tx.Msg = msg
tx.Errno = errno
return tx
}
func (r *Response) WithData(data interface{}) *Response {
tx := r
if tx.Errno != merrors.ErnoSuccess {
tx.IsSucc = false
}
tx.Data = data
return tx
}
func EchoResponse(ctx *gin.Context, resp *Response) {
if resp.Errno != merrors.ErnoSuccess {
resp.IsSucc = false
} else {
resp.IsSucc = true
}
ctx.JSON(http.StatusOK, resp)
}
Go
1
https://gitee.com/git-lz/go-tinyid.git
git@gitee.com:git-lz/go-tinyid.git
git-lz
go-tinyid
go-tinyid
v0.0.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891