response

package
v0.0.0-...-ddd1a7f Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetailedJsonError

func DetailedJsonError(err error) error

DetailedJsonError checks the type of json Error

func JSON

func JSON(w http.ResponseWriter, rsp *Response, headers map[string]string)

JSON is for default Golang writer. it marshals 'response'struct to JSON, escapes HTML & sets the Content-Type as application/json.

func ParseBody

func ParseBody(c *fiber.Ctx, payload any) error

Types

type Response

type Response struct {
	StatusCode        int     `json:"-"`
	Success           bool    `json:"success"`
	Message           string  `json:"message"`
	ErrorCode         *string `json:"errorCode,omitempty"`
	Data              any     `json:"data,omitempty"`
	RuntimeCallerInfo string  `json:"-"`
}

Response is the response structure.

func BadRequest

func BadRequest(msg string, errorCode *string) *Response

func Conflict

func Conflict(msg string, errorCode *string) *Response

func Created

func Created(msg string, data any) *Response

func Forbidden

func Forbidden(msg string, errorCode *string) *Response

func InternalServerError

func InternalServerError(msg string, errorCode *string) *Response

func NewError

func NewError(statusCode int, msg string, errorCode *string) *Response

func NewSuccess

func NewSuccess(statusCode int, msg string, data any) *Response

func NotFound

func NotFound(msg string, errorCode *string) *Response

func Ok

func Ok(msg string, data any) *Response

func Unauthorized

func Unauthorized(msg string, errorCode *string) *Response

func (Response) Error

func (a Response) Error() string

Lets do this, so the structs satisfy's go error interface

Jump to

Keyboard shortcuts

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