@@ -9,16 +9,16 @@ import (
|
||||
|
||||
type RespStatus struct {
|
||||
Code int `json:"code"`
|
||||
ErrorId string `json:"error_id"`
|
||||
Status string `json:"status"`
|
||||
ErrorId string `json:"error_id"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func render(c *gin.Context, code int, id string, status string, data []any, abort bool) {
|
||||
func render(c *gin.Context, code int, errId string, data []any, abort bool) {
|
||||
resp := RespStatus{
|
||||
Code: code,
|
||||
ErrorId: id,
|
||||
Status: status,
|
||||
Status: http.StatusText(code),
|
||||
ErrorId: errId,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
@@ -45,10 +45,10 @@ func render(c *gin.Context, code int, id string, status string, data []any, abor
|
||||
_, _ = c.Writer.Write(jsonBytes)
|
||||
}
|
||||
|
||||
func HttpResponse(c *gin.Context, code int, id string, status string, data ...any) {
|
||||
render(c, code, id, status, data, false)
|
||||
func HttpResponse(c *gin.Context, code int, errId string, data ...any) {
|
||||
render(c, code, errId, data, false)
|
||||
}
|
||||
|
||||
func HttpAbort(c *gin.Context, code int, id string, status string, data ...any) {
|
||||
render(c, code, id, status, data, true)
|
||||
func HttpAbort(c *gin.Context, code int, errId string, data ...any) {
|
||||
render(c, code, errId, data, true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user