response

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *gin.Context, message string)

BadRequest sends a bad request error

func Conflict

func Conflict(c *gin.Context, message string)

Conflict sends a conflict error

func Created

func Created(c *gin.Context, data interface{})

Created sends a created response

func Error

func Error(c *gin.Context, statusCode int, code string, message string)

Error sends an error response

func ErrorWithDetails

func ErrorWithDetails(c *gin.Context, statusCode int, code string, message string, details interface{})

ErrorWithDetails sends an error response with details

func Forbidden

func Forbidden(c *gin.Context, message string)

Forbidden sends a forbidden error

func InternalServerError

func InternalServerError(c *gin.Context, message string)

InternalServerError sends an internal server error

func NoContent

func NoContent(c *gin.Context)

NoContent sends a no content response

func NotFound

func NotFound(c *gin.Context, message string)

NotFound sends a not found error

func Success

func Success(c *gin.Context, data interface{})

Success sends a success response

func SuccessWithMeta

func SuccessWithMeta(c *gin.Context, data interface{}, meta *Meta)

SuccessWithMeta sends a success response with metadata

func Unauthorized

func Unauthorized(c *gin.Context, message string)

Unauthorized sends an unauthorized error

Types

type ErrorInfo

type ErrorInfo struct {
	Code    string      `json:"code"`
	Message string      `json:"message"`
	Details interface{} `json:"details,omitempty"`
}

ErrorInfo represents error information

type Meta

type Meta struct {
	Page       int   `json:"page,omitempty"`
	PerPage    int   `json:"per_page,omitempty"`
	Total      int64 `json:"total,omitempty"`
	TotalPages int   `json:"total_pages,omitempty"`
}

Meta represents response metadata

func NewMeta

func NewMeta(page, perPage int, total int64) *Meta

NewMeta creates pagination metadata

type Response

type Response struct {
	Success       bool        `json:"success"`
	Data          interface{} `json:"data,omitempty"`
	Error         *ErrorInfo  `json:"error,omitempty"`
	Meta          *Meta       `json:"meta,omitempty"`
	CorrelationID string      `json:"correlation_id,omitempty"`
}

Response represents a standard API response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL