Documentation

Overview

Package apigateway provides a standard serialization format to wrap API Gateway responses that translate into specific end-user errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    int                    `json:"code"`
	Err     string                 `json:"err"`
	Message string                 `json:"message"`
	Context map[string]interface{} `json:"context,omitempty"`
}

Error represents an error to return in response to an API Gateway request.

func NewErrorResponse

func NewErrorResponse(statusCode int, messages ...interface{}) *Error

NewErrorResponse returns a response that satisfies the regular expression used to determine integration mappings via the API Gateway. messages is a stringable type. Error interface instances will be properly typecast.

func (*Error) Error

func (apigError *Error) Error() string

Error returns the JSONified version of this error which will trigger the appropriate integration mapping.

type Response

type Response struct {
	Code    int               `json:"code,omitempty"`
	Body    interface{}       `json:"body,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

Response is the type returned by an API Gateway function. Note that a non 2xx HTTP status code should be returned as a Response type rather than an Error. Errors should be reserved for Lambda functions that fail to execute.

func NewResponse

func NewResponse(code int, body interface{}, headers ...map[string]string) *Response

NewResponse returns an API Gateway response object

func (*Response) MarshalJSON

func (resp *Response) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaller to ensure that the marshalled headers are always lowercase

Source Files