response

package
Version: v0.0.0-...-23b95e8 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BadRequest defines ErrorData data when returns 400 error response.
	BadRequest = ErrorData{
		HTTPStatus:       400,
		Property:         "bad_request",
		Message:          "The request is invalid or improperly formed.",
		DeveloperMessage: "The request is invalid or improperly formed.",
	}
	// Unauthorized defines ErrorData data when returns 400 error response.
	Unauthorized = ErrorData{
		HTTPStatus:       401,
		Property:         "unauthorized",
		Message:          "Invalid Credentials.",
		DeveloperMessage: "Invalid Credentials.",
	}
	// InsufficientPermission defines ErrorData data when returns 403 error response.
	InsufficientPermission = ErrorData{
		HTTPStatus:       403,
		Property:         "forbidden",
		Message:          "Does not have sufficient permissions.",
		DeveloperMessage: "Does not have sufficient permissions.",
	}
	// Forbidden defines ErrorData data when returns 403 error response.
	Forbidden = ErrorData{
		HTTPStatus:       403,
		Property:         "forbidden",
		Message:          "The request operation is forbidden and cannot be completed.",
		DeveloperMessage: "The request operation is forbidden and cannot be completed.",
	}
	// EndpointNotExists defines ErrorData data when is requested a invalid endpoint.
	EndpointNotExists = ErrorData{
		HTTPStatus:       404,
		Property:         "not_found",
		Message:          "Endpoint does not exist.",
		DeveloperMessage: "Endpoint does not exist.",
	}
	// DataNotFound defines ErrorData data when returns 404 error response.
	DataNotFound = ErrorData{
		HTTPStatus:       404,
		Property:         "not_found",
		Message:          "The requested data does not exist.",
		DeveloperMessage: "The requested data does not exist.",
	}
	// RequestEntityTooLarge defines ErrorData data when returns 413 error response.
	RequestEntityTooLarge = ErrorData{
		HTTPStatus:       413,
		Property:         "payload_too_large",
		Message:          "The data sent in the request is too large.",
		DeveloperMessage: "The data sent in the request is too large.",
	}
	// ResponseTooLarge defines ErrorData data when returns 413 error response.
	ResponseTooLarge = ErrorData{
		HTTPStatus:       413,
		Property:         "response_too_large",
		Message:          "The requested resource is too large to return.",
		DeveloperMessage: "The requested resource is too large to return.",
	}
	// RateLimitExceeded defines ErrorData data when returns 429 error response.
	RateLimitExceeded = ErrorData{
		HTTPStatus:       429,
		Property:         "rate_limit_exceeded",
		Message:          "API quota exceeded.",
		DeveloperMessage: "API quota exceeded.",
	}
	// DatabaseConnectError defines ErrorData data
	// when returns error response to fail to connect database.
	DatabaseConnectError = ErrorData{
		HTTPStatus:       500,
		Property:         "internal_server_error",
		Message:          "Failed to refer data storage.",
		DeveloperMessage: "Failed to refer data storage.",
	}
	// InternalServerError defines ErrorData data when returns 500 error response.
	InternalServerError = ErrorData{
		HTTPStatus:       500,
		Property:         "internal_server_error",
		Message:          "The request failed due to an internal error.",
		DeveloperMessage: "The request failed due to an internal error.",
	}
	// ServiceUnavailable defines ErrorData data when returns error response during matainance.
	ServiceUnavailable = ErrorData{
		HTTPStatus:       503,
		Property:         "service_unavailable",
		Message:          "Overloaded with requests. Please try again later..",
		DeveloperMessage: "Overloaded with requests. Please try again later..",
	}
)

Functions

func JSON

func JSON(c echo.Context, status int, i interface{}) (err error)

JSON sets Respose.Item is encoded json in echo.Context and returns error when happend some exception.

func String

func String(c echo.Context, status int, i interface{}) (err error)

String sets Respose.Item in echo.Context and returns error when happend some exception.

func XML

func XML(c echo.Context, status int, i interface{}) (err error)

XML sets Respose.Item is encoded XML in echo.Context and returns error when happend some exception.

Types

type ErrorData

type ErrorData struct {
	HTTPStatus       int    `json:"status",xml:"status"`
	Code             int    `json:"code,omitempty",xml:"code,omitempty"`
	Property         string `json:"property,omitempty",xml:"property,omitempty"`
	Message          string `json:"message",xml:"message"`
	DeveloperMessage string `json:"developerMessage",xml:"developerMessage"`
	MoreInfo         string `json:"moreInfo,omitempty",xml:"moreInfo,omitempty"`
}

ErrorData defines the information for error response messages and status.

func DecodeErrorData

func DecodeErrorData(jsonText string) (d ErrorData, err error)

DecodeErrorData create a new ErrorData from json text.

func DecodeResopnseAsErrorData

func DecodeResopnseAsErrorData(body string) (d ErrorData)

DecodeResopnseAsErrorData create a new ErrorData from internal API response. when invalid JSON response catches, InternalServerError is created.

type ErrorResponse

type ErrorResponse struct {
	Context          echo.Context
	ErrorInformation ErrorData
}

ErrorResponse defines the error response.

func NewErrorResponse

func NewErrorResponse(c echo.Context, e ErrorData) *ErrorResponse

NewErrorResponse creates a new ErrorResponse.

func (*ErrorResponse) Error

func (er *ErrorResponse) Error() string

Error returns error message string.

func (*ErrorResponse) JSON

func (er *ErrorResponse) JSON() (err error)

JSON sends a JSON response with status code.

func (*ErrorResponse) String

func (er *ErrorResponse) String() (err error)

String sends a String response with status code.

func (*ErrorResponse) XML

func (er *ErrorResponse) XML() (err error)

XML sends a XML response with status code.

type Link struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
}

Link defines the information to navigate the service.

type Links []*Link

Links bundles Link structure.

type Page

type Page struct {
	Href       string        `json:"href"`
	Offset     int           `json:"offset"`
	Limit      int           `json:"limit"`
	First      *string       `json:"first"`
	Previous   *string       `json:"previous"`
	Next       *string       `json:"next"`
	Last       *string       `json:"last"`
	Items      []interface{} `json:"items"`
	TotalItems int           `json:"total"`
}

Page defines the response type for REST hateoas. This type is used REST API outputs index data.

type Response

type Response struct {
	Context    echo.Context
	HTTPStatus int
	Item       interface{}
}

Response is the structure for http response.

func New

func New(c echo.Context, status int, i interface{}) *Response

New creates a new Response

func (*Response) Debug

func (r *Response) Debug() (result interface{}, err error)

Debug returns Response value is encoded json.

func (*Response) JSON

func (r *Response) JSON() (err error)

JSON sets Respose.Item is encoded json in echo.Context and returns error when happend some exception.

func (*Response) String

func (r *Response) String() (err error)

String sets Respose.Item in echo.Context and returns error when happend some exception.

func (*Response) XML

func (r *Response) XML() (err error)

XML sets Respose.Item is encoded XML in echo.Context and returns error when happend some exception.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to