Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 179157f49e |
@@ -3,6 +3,8 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -13,7 +15,8 @@ var Response Reply
|
||||
type Reply struct {
|
||||
Code int32 `json:"code"` // 响应码
|
||||
Message string `json:"message"` // 响应消息
|
||||
Result any `json:"result"` // 响应数据
|
||||
Details any `json:"details"` // 响应数据
|
||||
Timeseq int64 `json:"timeseq"` // 时间戳序列
|
||||
}
|
||||
|
||||
// Success 返回成功响应
|
||||
@@ -21,10 +24,11 @@ type Reply struct {
|
||||
// data: 响应数据
|
||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||
reply.Code = 0
|
||||
reply.Result = data
|
||||
reply.Details = data
|
||||
reply.Message = ""
|
||||
reply.Timeseq = time.Now().UnixMilli()
|
||||
if data == nil {
|
||||
reply.Result = ""
|
||||
reply.Details = ""
|
||||
}
|
||||
ctx.JSON(200, reply)
|
||||
}
|
||||
@@ -34,7 +38,7 @@ func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||
// err: 错误对象
|
||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||
reply.Code = 500
|
||||
reply.Result = ""
|
||||
reply.Details = ""
|
||||
// 默认状态码为500
|
||||
e, ok := status.FromError(err)
|
||||
if ok {
|
||||
|
||||
Reference in New Issue
Block a user