respond

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 4 Imported by: 0

README

respond

Custom wrapers to write http.ResponseWriter on success and failure cases. Failure case accepts errors.AppError and send the response has json.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CSV

CSV writes the text/csv response into the responsewriter

func Created

func Created(w http.ResponseWriter, data interface{}) *errors.AppError

Created is a helper function used to send response data with StatusCreated status code (201) NOTE: HTTP Method POST which creates any resource on the server should use status code (201)

func Fail

Fail write the error response Common func to send all the error response

func Msg

func Msg(msg interface{}) map[string]interface{}

Msg returns new json with message

func NoContent

func NoContent(w http.ResponseWriter, data interface{}) *errors.AppError

NoContent is a helper function used to send a NoContent Header (204) Note : the sent data and meta are ignored. NOTE: HTTP Methods DELETE should use status code (204)

func OK

func OK(w http.ResponseWriter, data interface{}) *errors.AppError

OK is a helper function used to send response data with StatusOK status code (200) NOTE: HTTP Methods GET, PUT should use status code (200)

Types

type Meta

type Meta struct {
	Status int `json:"status_code"`
}

Meta holds the status of the request informations TODO: add meta information for paginations

type Response

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

Response struct contains all the fields needed to respond to a particular request NOTE: we may add support for Metadata interface{}

func NewResponse

func NewResponse(statusCode int, data interface{}) *Response

NewResponse returns a new response object.

func (*Response) Send

func (res *Response) Send(w http.ResponseWriter) error

Send sends data encoded to JSON

Jump to

Keyboard shortcuts

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