48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package response
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Fail(c *gin.Context, status int, code int, message string) {
|
|
c.JSON(status, body(c, code, message, nil))
|
|
}
|
|
|
|
func BadRequest(c *gin.Context, message string) {
|
|
Fail(c, http.StatusBadRequest, CodeBadRequest, message)
|
|
}
|
|
|
|
func Unauthorized(c *gin.Context, message string) {
|
|
Fail(c, http.StatusUnauthorized, CodeUnauthorized, message)
|
|
}
|
|
|
|
func Forbidden(c *gin.Context, message string) {
|
|
Fail(c, http.StatusForbidden, CodeForbidden, message)
|
|
}
|
|
|
|
func NotFound(c *gin.Context, message string) {
|
|
Fail(c, http.StatusNotFound, CodeNotFound, message)
|
|
}
|
|
|
|
func Conflict(c *gin.Context, message string) {
|
|
Fail(c, http.StatusConflict, CodeConflict, message)
|
|
}
|
|
|
|
func PayloadTooLarge(c *gin.Context, message string) {
|
|
Fail(c, http.StatusRequestEntityTooLarge, CodePayloadLarge, message)
|
|
}
|
|
|
|
func TooManyRequests(c *gin.Context, message string) {
|
|
Fail(c, http.StatusTooManyRequests, CodeTooMany, message)
|
|
}
|
|
|
|
func ServerError(c *gin.Context, message string) {
|
|
Fail(c, http.StatusInternalServerError, CodeServerError, message)
|
|
}
|
|
|
|
func ServiceUnavailable(c *gin.Context, message string) {
|
|
Fail(c, http.StatusServiceUnavailable, CodeUnavailable, message)
|
|
}
|