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)
type SuccessResponse struct {
APIVersion string `json:"apiVersion"`
Code string `json:"code"`
Message string `json:"message"`
StatusCode int `json:"status_code"`
Data interface{} `json:"data"`
}
type FailResponse struct {
APIVersion string `json:"apiVersion"`
Error RespErr `json:"error"`
Code string `json:"code"`
Message string `json:"message"`
StatusCode int `json:"status_code"`
}
type RespErr struct {
......
......@@ -16,15 +16,17 @@ func AssembleResponse(c *gin.Context, data interface{}, err error, opts ...Respo
code = http.StatusInternalServerError
c.JSON(code, FailResponse{
APIVersion: APIVersion,
Error: RespErr{
Code: code,
Code: "ERROR",
Message: err.Error(),
},
StatusCode: code,
})
return
}
resp := SuccessResponse{
APIVersion: APIVersion,
Code: "OK",
Message: "success",
StatusCode: code,
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