fix infra response

This commit is contained in:
yanweidong 2025-04-18 19:11:50 +08:00
parent 6cd06d86bc
commit 52a81a404e
1 changed files with 10 additions and 10 deletions

View File

@ -8,29 +8,29 @@ import (
var Response Reply
type Reply struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data any `json:"data"`
Code int32 `json:"code"`
Message string `json:"message"`
Result any `json:"result"`
}
func (reply *Reply) Success(ctx *gin.Context, data any) {
reply.Code = 200
reply.Data = data
reply.Msg = ""
reply.Code = 0
reply.Result = data
reply.Message = ""
if data == nil {
reply.Data = ""
reply.Result = ""
}
ctx.JSON(200, reply)
}
func (reply *Reply) Error(ctx *gin.Context, err error) {
reply.Code = 500
reply.Data = ""
reply.Result = ""
// Status code defaults to 500
e, ok := status.FromError(err)
if ok {
reply.Code = int(e.Code())
reply.Code = int32(e.Code())
}
reply.Msg = e.Message()
reply.Message = e.Message()
// Send error
ctx.JSON(200, reply)