response

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INTERNAL_SERVER_ERROR = "internal_server_error"
	SUCCESS               = "success"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicResponse

type BasicResponse struct {
	Code    int         `json:"code" example:"500"`                      // HTTP status code.
	Message string      `json:"message" example:"internal_server_error"` // Message corresponding to the status code.
	Error   string      `json:"error" example:"{$err}"`                  // error message.
	Data    interface{} `json:"data,omitempty"`
}

BasicResponse represents a failed response structure for API responses.

func BasicBuilder

func BasicBuilder(result BasicResponse) BasicResponse

BasicBuilder constructs a BasicBuilder based on the provided error.

func (BasicResponse) Send

func (c BasicResponse) Send(ctx echo.Context) error

Send sends the CustomResponse as a JSON response using the provided Echo context.

type FailedResponse

type FailedResponse struct {
	Code    int    `json:"code" example:"500"`                      // HTTP status code.
	Message string `json:"message" example:"internal_server_error"` // Message corresponding to the status code.
	Error   string `json:"error" example:"{$err}"`                  // error message.
}

FailedResponse represents a failed response structure for API responses.

func ErrorBuilder

func ErrorBuilder(err error) FailedResponse

ErrorBuilder constructs a FailedResponse based on the provided error.

func (FailedResponse) Send

func (x FailedResponse) Send(c echo.Context) error

Send sends the CustomResponse as a JSON response using the provided Echo context.

type Meta

type Meta struct {
	Meta interface{} `json:"meta,omitempty"` //pagination payload.
	Success
}

type ResponseFormat

type ResponseFormat struct {
	Code    int    `json:"code" example:"200"` // HTTP status code.
	Message string `json:"message" example:"success"`
}

type Success

type Success struct {
	ResponseFormat
	Data interface{} `json:"data,omitempty"` // data payload.
}

type SuccessResponse

type SuccessResponse struct {
	Success
	Meta
}

SuccessResponse represents a success response structure for API responses.

func SuccessBuilder

func SuccessBuilder(response interface{}, meta ...interface{}) SuccessResponse

SuccessBuilder constructs a CustomResponse with a Success status and the provided response data.

func (SuccessResponse) Send

func (c SuccessResponse) Send(ctx echo.Context) error

Send sends the CustomResponse as a JSON response using the provided Echo context.

Jump to

Keyboard shortcuts

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