Commit 2840d98a authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Update response types and utility functions

- Add `Code`, `Message`, and `StatusCode` fields to `SuccessResponse` and `FailResponse`
- Remove `RespErr` struct and directly include error details in `FailResponse`
- Modify `AssembleResponse` to use new response structure with standardized fields
parent 3e867e01
...@@ -4,12 +4,17 @@ type ResponseDataOptionFunc func(ev *SuccessResponse) ...@@ -4,12 +4,17 @@ type ResponseDataOptionFunc func(ev *SuccessResponse)
type SuccessResponse struct { type SuccessResponse struct {
APIVersion string `json:"apiVersion"` APIVersion string `json:"apiVersion"`
Code string `json:"code"`
Message string `json:"message"`
StatusCode int `json:"status_code"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
type FailResponse struct { type FailResponse struct {
APIVersion string `json:"apiVersion"` APIVersion string `json:"apiVersion"`
Error RespErr `json:"error"` Code string `json:"code"`
Message string `json:"message"`
StatusCode int `json:"status_code"`
} }
type RespErr struct { type RespErr struct {
......
...@@ -16,15 +16,17 @@ func AssembleResponse(c *gin.Context, data interface{}, err error, opts ...Respo ...@@ -16,15 +16,17 @@ func AssembleResponse(c *gin.Context, data interface{}, err error, opts ...Respo
code = http.StatusInternalServerError code = http.StatusInternalServerError
c.JSON(code, FailResponse{ c.JSON(code, FailResponse{
APIVersion: APIVersion, APIVersion: APIVersion,
Error: RespErr{ Code: "ERROR",
Code: code,
Message: err.Error(), Message: err.Error(),
}, StatusCode: code,
}) })
return return
} }
resp := SuccessResponse{ resp := SuccessResponse{
APIVersion: APIVersion, APIVersion: APIVersion,
Code: "OK",
Message: "success",
StatusCode: code,
Data: data, Data: data,
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment