48 lines
867 B
Go
48 lines
867 B
Go
// 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,
|
|
},
|
|
})
|
|
}
|