Use utils.HttpResponse/Abort to replace c.JSON/Abort
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
30
utils/response.go
Normal file
30
utils/response.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type RespStatus struct {
|
||||
Code int `json:"code"`
|
||||
ErrorId string `json:"error_id"`
|
||||
Status string `json:"status"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func HttpResponse(c *gin.Context, code int, errorId string, status string, data ...any) {
|
||||
var resp = RespStatus{
|
||||
Code: code,
|
||||
ErrorId: errorId,
|
||||
Status: status,
|
||||
Data: data,
|
||||
}
|
||||
c.JSON(code, resp)
|
||||
}
|
||||
|
||||
func HttpAbort(c *gin.Context, code int, errorId string, status string, data ...any) {
|
||||
var resp = RespStatus{
|
||||
Code: code,
|
||||
ErrorId: errorId,
|
||||
Status: status,
|
||||
Data: data,
|
||||
}
|
||||
c.AbortWithStatusJSON(code, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user