代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。