mirror of
https://github.com/Dvorinka/SEEN.git
synced 2026-06-04 12:33:02 +00:00
35 lines
575 B
Go
35 lines
575 B
Go
package httpx
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
type ErrorResponse struct {
|
|
Error string `json:"error"`
|
|
RequestID string `json:"requestId,omitempty"`
|
|
}
|
|
|
|
func JSONError(c *gin.Context, status int, message string) {
|
|
requestID, _ := c.Get("request_id")
|
|
|
|
c.JSON(status, ErrorResponse{
|
|
Error: message,
|
|
RequestID: toString(requestID),
|
|
})
|
|
}
|
|
|
|
func JSON(c *gin.Context, status int, payload any) {
|
|
c.JSON(status, payload)
|
|
}
|
|
|
|
func toString(value any) string {
|
|
if value == nil {
|
|
return ""
|
|
}
|
|
|
|
typed, ok := value.(string)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
|
|
return typed
|
|
}
|