response

package
v0.0.0-...-ca0f7d1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const NotLoggedInErrorText = "You are not logged in"

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(w http.ResponseWriter)

BadRequest replies to the request with an HTTP 404 Given Param is not valid

func CreateBoundLogger

func CreateBoundLogger(logger log.Interface) func(r *http.Request) log.Interface

CreateBoundLogger create error response generator Method will log error

func Error

func Error(w http.ResponseWriter, statusCode int, errMessage string)

Error basic function to send any type of Error

func InternalServerError

func InternalServerError(w http.ResponseWriter)

InternalServerError replies to the request with an HTTP 500 Internal Server Error error

func NotAllowed

func NotAllowed(w http.ResponseWriter)

NotAllowed replies to the request with an HTTP 405 Method Not Allowed

func NotFound

func NotFound(w http.ResponseWriter)

NotFound replies to the request with an HTTP 404 Not Found error

func NotLoggedInError

func NotLoggedInError(w http.ResponseWriter)

func OK

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

OK response with 200 status code and data in payload

func OKWithResponseCode

func OKWithResponseCode(w http.ResponseWriter, statusCode int, data interface{})

OKWithResponseCode response with 2xx status code

func OKWithoutContent

func OKWithoutContent(w http.ResponseWriter)

OKWithoutContent response with 204 status code

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, url string, code int)

Types

type ErrorData

type ErrorData struct {
	Code    int         `json:"code"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

ErrorData represents error in error response

type ErrorResponse

type ErrorResponse struct {
	ErrorData ErrorData `json:"error"`
}

ErrorResponse represents error response

type SuccessResponse

type SuccessResponse struct {
	Data interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

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