结构修改
This commit is contained in:
12
response.go
12
response.go
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user