response

package
v0.0.0-...-8f202a6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServer = CustomResponse{
		HttpCode: http.StatusInternalServerError,
		Message:  "internal server error",
		Code:     "5000",
	}

	ErrBadRequest = CustomResponse{
		HttpCode: http.StatusBadRequest,
		Message:  "bad request",
		Code:     "4000",
	}

	ErrUnauthorized = CustomResponse{
		HttpCode: http.StatusUnauthorized,
		Message:  "Api-Key invalid",
		Code:     "4001",
	}

	ErrInvalidParam = CustomResponse{
		HttpCode: http.StatusBadRequest,
		Message:  "invalid parameter",
		Code:     "4003",
	}

	ErrForbidden = CustomResponse{
		HttpCode: http.StatusForbidden,
		Message:  http.StatusText(http.StatusForbidden),
		Code:     "4003",
	}

	ErrRecordNotFound = CustomResponse{
		HttpCode: http.StatusNotFound,
		Message:  "record not found",
		Code:     "4004",
	}

	ErrUnprocessableEntity = CustomResponse{
		HttpCode: http.StatusUnprocessableEntity,
		Message:  "StatusUnprocessableEntity",
		Code:     "4002",
	}

	StatusTooManyRequests = CustomResponse{
		HttpCode: http.StatusTooManyRequests,
		Message:  "StatusTooManyRequests",
		Code:     "4005",
	}
)
View Source
var (
	Ok = CustomResponse{
		HttpCode: http.StatusOK,
		Message:  "success",
		Code:     "0000",
	}

	SuccessMessage = "success"
)

Functions

func Build

func Build(ctx *fiber.Ctx, ce CustomResponse)

Types

type CustomResponse

type CustomResponse struct {
	HttpCode   int         `json:"http_code"`
	Message    string      `json:"message"`
	Code       string      `json:"code"`
	Detail     string      `json:"detail,omitempty"`
	Data       interface{} `json:"data,omitempty"`
	Pagination interface{} `json:"pagination,omitempty"`
	Errors     []ErrorInfo `json:"errors,omitempty"`
}

func (CustomResponse) Error

func (e CustomResponse) Error() string

func (CustomResponse) WithData

func (e CustomResponse) WithData(data interface{}) CustomResponse

func (CustomResponse) WithDetail

func (e CustomResponse) WithDetail(detail string) CustomResponse

func (CustomResponse) WithError

func (e CustomResponse) WithError(err error) CustomResponse

func (CustomResponse) WithErrorInfo

func (e CustomResponse) WithErrorInfo(errInfo []ErrorInfo) CustomResponse

func (CustomResponse) WithPagination

func (e CustomResponse) WithPagination(data interface{}, page int, perPage int, total int) CustomResponse

func (CustomResponse) WithValidationError

func (e CustomResponse) WithValidationError(err error) CustomResponse

type ErrorInfo

type ErrorInfo struct {
	Field        string `json:"field"`
	ErrorMessage string `json:"error_message"`
}

type ListResponse

type ListResponse struct {
	Meta MetaResponse `json:"meta"`
	Data interface{}  `json:"data"`
}

type MetaResponse

type MetaResponse struct {
	Page       int   `json:"page"`
	Limit      int   `json:"limit"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"total_pages"`
}

Jump to

Keyboard shortcuts

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