结构修改

This commit is contained in:
2025-12-09 16:17:38 +08:00
parent edf1a1f5ca
commit fd03cc08a7
2 changed files with 22 additions and 68 deletions

View File

@@ -1,7 +1,6 @@
package response
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
@@ -19,7 +18,7 @@ func getErrorCodeAndMessage(err error) (int, string) {
if st, ok := status.FromError(err); ok {
return int(st.Code()), st.Message()
}
return CodeInternalServerError, "未知错误类型或内部服务错误"
return CodeFaild, "未知错误类型或内部服务错误"
}
func Result(c *gin.Context, err error, data any) {
@@ -32,10 +31,6 @@ func Result(c *gin.Context, err error, data any) {
httpStatus := http.StatusOK
if code == CodeInternalServerError || !errors.Is(err, ErrSuccess) && code == 0 {
httpStatus = http.StatusInternalServerError
}
c.JSON(httpStatus, Response{
Code: code,
Message: message,
@@ -53,10 +48,6 @@ func PageResult(c *gin.Context, err error, total int64, data any) {
httpStatus := http.StatusOK
if code == CodeInternalServerError || !errors.Is(err, ErrSuccess) && code == 0 {
httpStatus = http.StatusInternalServerError
}
c.JSON(httpStatus, Response{
Code: code,
Message: message,
@@ -64,4 +55,3 @@ func PageResult(c *gin.Context, err error, total int64, data any) {
Data: data,
})
}