New
This commit is contained in:
47
internal/response/response.go
Normal file
47
internal/response/response.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Filename: internal/response/response.go
|
||||
package response
|
||||
|
||||
import (
|
||||
"gemini-balancer/internal/errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SuccessResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ErrorResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Error gin.H `json:"error"`
|
||||
}
|
||||
|
||||
func Success(c *gin.Context, data interface{}) {
|
||||
c.JSON(http.StatusOK, SuccessResponse{
|
||||
Success: true,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
func Created(c *gin.Context, data interface{}) {
|
||||
c.JSON(http.StatusCreated, SuccessResponse{
|
||||
Success: true,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
func NoContent(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func Error(c *gin.Context, err *errors.APIError) {
|
||||
c.JSON(err.HTTPStatus, ErrorResponse{
|
||||
Success: false,
|
||||
Error: gin.H{
|
||||
"code": err.Code,
|
||||
"message": err.Message,
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user