package server import ( "net/http" "github.com/gin-gonic/gin" ) // APIResponse represents the unified JSON structure for all API responses. type APIResponse struct { Success bool `json:"success"` Data interface{} `json:"data,omitempty"` Error string `json:"error,omitempty"` } // OK responds with 200 and success data. func OK(c *gin.Context, data interface{}) { c.JSON(http.StatusOK, APIResponse{Success: true, Data: data}) } // Created responds with 201 and success data. func Created(c *gin.Context, data interface{}) { c.JSON(http.StatusCreated, APIResponse{Success: true, Data: data}) } // BadRequest responds with 400 and an error message. func BadRequest(c *gin.Context, msg string) { c.JSON(http.StatusBadRequest, APIResponse{Success: false, Error: msg}) } // NotFound responds with 404 and an error message. func NotFound(c *gin.Context, msg string) { c.JSON(http.StatusNotFound, APIResponse{Success: false, Error: msg}) } // InternalError responds with 500 and an error message. func InternalError(c *gin.Context, msg string) { c.JSON(http.StatusInternalServerError, APIResponse{Success: false, Error: msg}) } // ErrorWithStatus responds with a custom status code and an error message. func ErrorWithStatus(c *gin.Context, code int, msg string) { c.JSON(code, APIResponse{Success: false, Error: msg}) }