global

package
v0.0.0-...-2bb31bb Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ResponseStatus = struct {
	FailedResponse  string
	SuccessResponse string
	RetryResponse   string
}{
	FailedResponse:  "FAILED",
	SuccessResponse: "OK",
	RetryResponse:   "RETRY",
}

Functions

func CreateMessageResponse

func CreateMessageResponse(message string, statusCode int, c *fiber.Ctx) error

func CreateResponse

func CreateResponse[T any](data *T, statusCode int, c *fiber.Ctx) error

func MessageResponse

func MessageResponse(message string, statusCode int, c *fiber.Ctx) error

Types

type ErrorResponse

type ErrorResponse interface {
	Error() string
	GetMessage() string
	GetCode() int
	GetData() interface{}
	ToResponse(c *fiber.Ctx) error
	GetStack() string
}

func BadRequestError

func BadRequestError(message string) ErrorResponse

func BadRequestErrorWithData

func BadRequestErrorWithData(message string, data interface{}) ErrorResponse

func ForbiddenError

func ForbiddenError() ErrorResponse

func InternalServerError

func InternalServerError(err error) ErrorResponse

func NotFoundError

func NotFoundError(messages ...string) ErrorResponse

func UnauthorizedError

func UnauthorizedError() ErrorResponse

type Response

type Response[T any] struct {
	Code    int    `json:"code"`
	Status  string `json:"status"`
	Data    T      `json:"data"`
	Message string `json:"message"`
}

type Result

type Result[T any] struct {
	Data       *T
	Error      error
	StatusCode int
}

func (*Result[T]) ToResponseError

func (r *Result[T]) ToResponseError() *Response[*T]

Jump to

Keyboard shortcuts

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