responses

package
Version: v0.0.0-...-a6a5f53 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServerError = ErrorPayload{Error: Error{Code: "error:internal_server_error", Description: "Internal Server Error"}}
	ErrInvalidBody         = ErrorPayload{Error: Error{Code: "error:invalid_body", Description: "Invalid body"}}
	ErrInvalidParams       = ErrorPayload{Error: Error{Code: "error:invalid_parameters", Description: "Invalid query parameters"}}
	ErrNotImplemented      = ErrorPayload{Error: Error{Code: "error:not_implemented", Description: "Not implemented"}}
)

shared

View Source
var (
	ErrAccountNotFound     = ErrorPayload{Error: Error{Code: "error:account_not_found", Description: "Account not found"}}
	ErrInsufficientBalance = ErrorPayload{Error: Error{Code: "error:insufficient_balance", Description: "Insufficient balance"}}
	ErrInsufficientCredit  = ErrorPayload{Error: Error{Code: "error:insufficient_credit", Description: "Insufficient credit"}}
	ErrInvalidAccID        = ErrorPayload{Error: Error{Code: "error:invalid_account_id", Description: "Account id must be a UUIDv4"}}
	ErrInvalidAmount       = ErrorPayload{Error: Error{Code: "error:invalid_amount", Description: "Amount must be greater than 0"}}
	ErrInvalidOperation    = ErrorPayload{Error: Error{Code: "error:invalid_operation", Description: "Invalid operation"}}
)

accounts

Functions

func SendJSON

func SendJSON(w http.ResponseWriter, payload interface{}, statusCode int) error

SendJSON responds requests based on

Types

type Error

type Error struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

Error code & description

type ErrorPayload

type ErrorPayload struct {
	Error `json:"errors"`
}

ErrorPayload represents error response payload

type Response

type Response struct {
	Status  int
	Error   error
	Payload interface{}
	// contains filtered or unexported fields
}

Response represents an API response

func Accepted

func Accepted(payload interface{}) Response

Accepted 202

func BadRequest

func BadRequest(err error, payload ErrorPayload) Response

BadRequest 400

func Conflict

func Conflict(err error, payload ErrorPayload) Response

Conflict 409

func Created

func Created(payload interface{}) Response

Created 201

func ErrorResponse

func ErrorResponse(err error) Response

ErrorResponse maps response error

func InternalServerError

func InternalServerError(err error) Response

InternalServerError 500

func NoContent

func NoContent() Response

NoContent 204

func NotFound

func NotFound(err error, payload ErrorPayload) Response

NotFound 404

func NotImplemented

func NotImplemented(err error) Response

NotImplemented 501

func OK

func OK(payload interface{}) Response

OK 200

func Unauthorized

func Unauthorized(err error, payload ErrorPayload) Response

Unauthorized 401

func UnprocessableEntity

func UnprocessableEntity(err error, payload ErrorPayload) Response

UnprocessableEntity 422

func (*Response) Headers

func (r *Response) Headers() map[string]string

Headers list response headers

func (*Response) SetHeader

func (r *Response) SetHeader(key, value string)

SetHeader set response header

Source Files

Jump to

Keyboard shortcuts

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