response

package
v0.0.0-...-d5b0c82 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest       = errors.New("bad request")
	ErrJWTInternalError = errors.New("jwt internal error")
	ErrNotFound         = errors.New("resource not found")
	ErrUnauthorized     = errors.New("unauthorized")
	ErrInternalError    = errors.New("internal error")
	ErrInvalidToken     = errors.New("invalid token")
	ErrExpiredToken     = errors.New("expired token")
	ErrStolenToken      = errors.New("stolen token")
	ErrInvalidObjectID  = errors.New("invalid object id")
	ErrValidation       = errors.New("validation error")
)

Generic error represents a generic error response.

Functions

func CreatedResponse

func CreatedResponse(c *gin.Context, msg string, data interface{})

CreatedResponse is a helper function that writes a JSON response to the provided gin.Context with an HTTP status of http.StatusCreated. The response includes the provided message and the provided data.

func ErrorResponse

func ErrorResponse(c *gin.Context, err *Error)

ErrorResponse writes a JSON response to the provided gin.Context with an HTTP status corresponding to the error code. The response includes the error message.

func OkResponse

func OkResponse(c *gin.Context, msg string, data interface{})

OkResponse is a helper function that writes a JSON response to the provided gin.Context with an HTTP status of http.StatusOK. The response includes the provided message and the provided data.

func ValidateErrorResponse

func ValidateErrorResponse(c *gin.Context, err error)

ValidateErrorResponse writes a JSON response to the provided gin.Context with an HTTP status corresponding to the error code. The response includes the error message and a list of validation error messages, if any.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents a composite error that contains both an application-level error and a service-level error.

func NewError

func NewError(appErr, serviceErr error) *Error

NewError creates a new Error instance with the given application-level and service-level errors.

func (*Error) AppErr

func (e *Error) AppErr() string

AppErr returns the application-level error associated with the Error.

func (*Error) Code

func (e *Error) Code() int

Code returns the appropriate HTTP status code based on the application-level error associated with the Error.

func (*Error) Error

func (e *Error) Error() string

Error returns a string representation of the composite error, which includes both the application-level error and the service-level error.

func (*Error) ServiceErr

func (e *Error) ServiceErr() string

ServiceErr returns the service-level error associated with the Error.

type TDataResponse

type TDataResponse struct {
	TResponse
	Data interface{} `json:"data"`
}

TDataResponse is a response type that includes a data field. It embeds the TResponse struct and adds a Data field to hold the response data.

type TErrResponse

type TErrResponse struct {
	TResponse
	Errors interface{} `json:"errors"`
}

TErrResponse is a response type that includes an error field. It embeds the TResponse struct and adds an Errors field to hold any errors that occurred.

type TResponse

type TResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

TResponse is a struct that represents a basic response from the API. It contains a code field to indicate the response status and a message field to provide additional context.

Jump to

Keyboard shortcuts

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