irs

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

filename: 3xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

filename: 4xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

filename: 5xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

filename: codes.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

filename: errors.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

filename: statuses.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

Index

Constants

This section is empty.

Variables

View Source
var ResponseStatuses = map[Code]Status{
	Ok: {http.StatusOK, "SUCCESS/OK"},

	BadRequest:                   {http.StatusBadRequest, "ERRORS/REQUEST/BAD_REQUEST"},
	Unauthorized:                 {http.StatusUnauthorized, "ERRORS/REQUEST/UNAUTHORIZED"},
	PaymentRequired:              {http.StatusPaymentRequired, "ERRORS/REQUEST/PAYMENT_REQUIRED"},
	Forbidden:                    {http.StatusForbidden, "ERRORS/REQUEST/FORBIDDEN"},
	NotFound:                     {http.StatusNotFound, "ERRORS/REQUEST/NOT_FOUND"},
	MethodNotAllowed:             {http.StatusMethodNotAllowed, "ERRORS/REQUEST/METHOD_NOT_ALLOWED"},
	NotAcceptable:                {http.StatusNotAcceptable, "ERRORS/REQUEST/NOT_ACCEPTABLE"},
	ProxyAuthRequired:            {http.StatusProxyAuthRequired, "ERRORS/REQUEST/PROXY_AUTH_REQUIRED"},
	RequestTimeout:               {http.StatusRequestTimeout, "ERRORS/REQUEST/REQUEST_TIMEOUT"},
	Conflict:                     {http.StatusConflict, "ERRORS/REQUEST/CONFLICT"},
	Gone:                         {http.StatusGone, "ERRORS/REQUEST/GONE"},
	LengthRequired:               {http.StatusLengthRequired, "ERRORS/REQUEST/LENGTH_REQUIRED"},
	PreconditionFailed:           {http.StatusPreconditionFailed, "ERRORS/REQUEST/PRECONDITION_FAILED"},
	RequestEntityTooLarge:        {http.StatusRequestEntityTooLarge, "ERRORS/REQUEST/REQUEST_ENTITY_TOO_LARGE"},
	RequestURITooLong:            {http.StatusRequestURITooLong, "ERRORS/REQUEST/REQUEST_URI_TOO_LONG"},
	UnsupportedMediaType:         {http.StatusUnsupportedMediaType, "ERRORS/REQUEST/UNSUPPORTED_MEDIA_TYPE"},
	RequestedRangeNotSatisfiable: {http.StatusRequestedRangeNotSatisfiable, "ERRORS/REQUEST/REQUESTED_RANGE_NOT_SATISFIABLE"},
	ExpectationFailed:            {http.StatusExpectationFailed, "ERRORS/REQUEST/EXPECTATION_FAILED"},
	Teapot:                       {http.StatusTeapot, "ERRORS/REQUEST/TEAPOT"},
	MisdirectedRequest:           {http.StatusMisdirectedRequest, "ERRORS/REQUEST/MISDIRECTED_REQUEST"},
	UnprocessableEntity:          {http.StatusUnprocessableEntity, "ERRORS/REQUEST/UNPROCESSABLE_ENTITY"},
	Locked:                       {http.StatusLocked, "ERRORS/REQUEST/LOCKED"},
	FailedDependency:             {http.StatusFailedDependency, "ERRORS/REQUEST/FAILED_DEPENDENCY"},
	TooEarly:                     {http.StatusTooEarly, "ERRORS/REQUEST/TOO_EARLY"},
	UpgradeRequired:              {http.StatusUpgradeRequired, "ERRORS/REQUEST/UPGRADE_REQUIRED"},
	PreconditionRequired:         {http.StatusPreconditionRequired, "ERRORS/REQUEST/PRECONDITION_REQUIRED"},
	TooManyRequests:              {http.StatusTooManyRequests, "ERRORS/REQUEST/TOO_MANY_REQUEST"},
	RequestHeaderFieldsTooLarge:  {http.StatusRequestHeaderFieldsTooLarge, "ERRORS/REQUEST/REQUEST_HEADER_FIELDS_TOO_LARGE"},
	UnavailableForLegalReasons:   {http.StatusUnavailableForLegalReasons, "ERRORS/REQUEST/UNAVAILABLE_FOR_LEGAL_REASONS"},

	InternalServerError:           {http.StatusInternalServerError, "ERRORS/REQUEST/INTERNAL_SERVER_ERROR"},
	NotImplemented:                {http.StatusNotImplemented, "ERRORS/REQUEST/NOT_IMPLEMENTED"},
	BadGateway:                    {http.StatusBadGateway, "ERRORS/REQUEST/BAD_GATEWAY"},
	ServiceUnavailable:            {http.StatusServiceUnavailable, "ERRORS/REQUEST/SERVICE_UNAVAILABLE"},
	GatewayTimeout:                {http.StatusGatewayTimeout, "ERRORS/REQUEST/GATEWAY_TIMEOUT"},
	HTTPVersionNotSupported:       {http.StatusHTTPVersionNotSupported, "ERRORS/REQUEST/HTTP_VERSION_NOT_SUPPORTED"},
	VariantAlsoNegotiates:         {http.StatusVariantAlsoNegotiates, "ERRORS/REQUEST/VARIANT_ALSO_NEGOTIATES"},
	InsufficientStorage:           {http.StatusInsufficientStorage, "ERRORS/REQUEST/INSUFFICIENT_STORAGE"},
	LoopDetected:                  {http.StatusLoopDetected, "ERRORS/REQUEST/LOOP_DETECTED"},
	NotExtended:                   {http.StatusNotExtended, "ERRORS/REQUEST/NOT_EXTENDED"},
	NetworkAuthenticationRequired: {http.StatusNetworkAuthenticationRequired, "ERRORS/REQUEST/NETWORK_AUTHENTICATION_REQUIRED"},
}

Functions

func AddStatus

func AddStatus(code Code, httpCode int, message string)

func MakeBadRequest

func MakeBadRequest(message ...interface{}) error

Description :

This function is a short hand for sending a http 400 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeCodeError

func MakeCodeError(code Code, err ...error) error

func MakeConflict

func MakeConflict(message ...interface{}) error

Description :

This function is a short hand for sending a http 408 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeForbidden

func MakeForbidden(message ...interface{}) error

Description :

This function is a short hand for sending a http 403 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeHttpError

func MakeHttpError(httpCode int, message ...interface{}) error

func MakeInsufficientStorage

func MakeInsufficientStorage(err error, message ...interface{}) error

Description :

This function is a short hand for sending a http 507 error

Parameters :

     err error : Required
         The error that causes the request fail. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeInternalServerError

func MakeInternalServerError(err error, message ...interface{}) error

Description :

This function is a short hand for sending a http 500 error

Parameters :

     err error : Required
         The error that causes the request fail. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeLengthRequired

func MakeLengthRequired(message ...interface{}) error

Description :

This function is a short hand for sending a http 411 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeMethodNotAllowed

func MakeMethodNotAllowed(message ...interface{}) error

Description :

This function is a short hand for sending a http 405 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeNotAcceptable

func MakeNotAcceptable(message ...interface{}) error

Description :

This function is a short hand for sending a http 406 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeNotFound

func MakeNotFound(message ...interface{}) error

Description :

This function is a short hand for sending a http 404 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeNotImplemented

func MakeNotImplemented(err error, message ...interface{}) error

Description :

This function is a short hand for sending a http 501 error

Parameters :

     err error : Required
         The error that causes the request fail. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeRequestEntityTooLarge

func MakeRequestEntityTooLarge(message ...interface{}) error

Description :

This function is a short hand for sending a http 413 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeRequestTimeout

func MakeRequestTimeout(message ...interface{}) error

Description :

This function is a short hand for sending a http 408 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeRequestedRangeNotSatisfiable

func MakeRequestedRangeNotSatisfiable(message ...interface{}) error

Description :

This function is a short hand for sending a http 416 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeServerError

func MakeServerError(httpCode int, err error, message ...interface{}) error

func MakeServiceUnavailable

func MakeServiceUnavailable(err error, message ...interface{}) error

Description :

This function is a short hand for sending a http 503 error

Parameters :

     err error : Required
         The error that causes the request fail. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeTeapot

func MakeTeapot(message ...interface{}) error

Description :

This function is a short hand for sending a http 418 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeUnauthorized

func MakeUnauthorized(message ...interface{}) error

Description :

This function is a short hand for sending a http 401 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func MakeUnsupportedMediaType

func MakeUnsupportedMediaType(message ...interface{}) error

Description :

This function is a short hand for sending a http 415 error

Parameters :

     c echo.Context : Required
         The current request context from echo. Must never be set to nil.
		message ...interface{} : Optional
			Informations about the response. Used to fill the message field of the response template.

Returns :

error :
	The encountered error if there has one. Nil otherwise

func SendFound

func SendFound(c echo.Context, url string) error

Description :

This function is a short hand for sending a http 302 response

Parameters :

     c echo.Context :
         The current request context from echo. Must never be set to nil.
		url string :
			The url to redirect

Returns :

error :
	The encountered error if there has one. Nil otherwise

func SendMovedPermanently

func SendMovedPermanently(c echo.Context, url string) error

Description :

This function is a short hand for sending a http 301 response

Parameters :

     c echo.Context :
         The current request context from echo. Must never be set to nil.
		url string :
			The url to redirect

Returns :

error :
	The encountered error if there has one. Nil otherwise

func SendPermanentRedirect

func SendPermanentRedirect(c echo.Context, url string) error

Description :

This function is a short hand for sending a http 308 response

Parameters :

     c echo.Context :
         The current request context from echo. Must never be set to nil.
		url string :
			The url to redirect

Returns :

error :
	The encountered error if there has one. Nil otherwise

func SendTemporaryRedirect

func SendTemporaryRedirect(c echo.Context, url string) error

Description :

This function is a short hand for sending a http 307 response

Parameters :

     c echo.Context :
         The current request context from echo. Must never be set to nil.
		url string :
			The url to redirect

Returns :

error :
	The encountered error if there has one. Nil otherwise

Types

type Code

type Code int
const (
	Ok Code = iota

	// Theses codes are defaults errcode for http codes.
	// This allow IRSA to handle echo errors and provide nice codes
	//
	// Some (iota + weird numbers) are required because every 400 codes does not follows
	// (So we step over them)
	BadRequest                   Code = iota + 399 // RFC 7231, 6.5.1
	Unauthorized                                   // RFC 7235, 3.1
	PaymentRequired                                // RFC 7231, 6.5.2
	Forbidden                                      // RFC 7231, 6.5.3
	NotFound                                       // RFC 7231, 6.5.4
	MethodNotAllowed                               // RFC 7231, 6.5.5
	NotAcceptable                                  // RFC 7231, 6.5.6
	ProxyAuthRequired                              // RFC 7235, 3.2
	RequestTimeout                                 // RFC 7231, 6.5.7
	Conflict                                       // RFC 7231, 6.5.8
	Gone                                           // RFC 7231, 6.5.9
	LengthRequired                                 // RFC 7231, 6.5.10
	PreconditionFailed                             // RFC 7232, 4.2
	RequestEntityTooLarge                          // RFC 7231, 6.5.11
	RequestURITooLong                              // RFC 7231, 6.5.12
	UnsupportedMediaType                           // RFC 7231, 6.5.13
	RequestedRangeNotSatisfiable                   // RFC 7233, 4.4
	ExpectationFailed                              // RFC 7231, 6.5.14
	Teapot                                         // RFC 7168, 2.3.3
	MisdirectedRequest           Code = iota + 401 // RFC 7540, 9.1.2
	UnprocessableEntity                            // RFC 4918, 11.2
	Locked                                         // RFC 4918, 11.3
	FailedDependency                               // RFC 4918, 11.4
	TooEarly                                       // RFC 8470, 5.2.
	UpgradeRequired                                // RFC 7231, 6.5.15
	PreconditionRequired         Code = iota + 402 // RFC 6585, 3
	TooManyRequests                                // RFC 6585, 4
	RequestHeaderFieldsTooLarge  Code = iota + 403 // RFC 6585, 5
	UnavailableForLegalReasons   Code = iota + 422 // RFC 7725, 3

	InternalServerError           Code = iota + 470 // RFC 7231, 6.6.1
	NotImplemented                                  // RFC 7231, 6.6.2
	BadGateway                                      // RFC 7231, 6.6.3
	ServiceUnavailable                              // RFC 7231, 6.6.4
	GatewayTimeout                                  // RFC 7231, 6.6.5
	HTTPVersionNotSupported                         // RFC 7231, 6.6.6
	VariantAlsoNegotiates                           // RFC 2295, 8.1
	InsufficientStorage                             // RFC 4918, 11.5
	LoopDetected                                    // RFC 5842, 7.2
	NotExtended                   Code = iota + 471 // RFC 2774, 7
	NetworkAuthenticationRequired                   // RFC 6585, 6

	StatusPadding = 1000
)

func (Code) Error

func (c Code) Error() string

func (Code) HttpCode

func (c Code) HttpCode() int

func (Code) Message

func (c Code) Message() string

type HttpError

type HttpError struct {
	HttpCode int    `json:"httpCode"`
	ErrCode  Code   `json:"errCode"`
	Message  string `json:"message"`
}

func (HttpError) Error

func (n HttpError) Error() string

type ServerError

type ServerError struct {
	HttpError
	Err error `json:"err"`
}

func (ServerError) Error

func (n ServerError) Error() string

type Status

type Status struct {
	HttpCode int
	Message  string
}

Directories

Path Synopsis
filename: 2xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: error.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: respond.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published
filename: 2xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: error.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: respond.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published
filename: 2xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: error.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: respond.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published
filename: 2xx.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: error.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published filename: respond.go author: Thomas Lombard copyright: Thomas Lombard license: MIT status: published

Jump to

Keyboard shortcuts

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