Documentation ¶
Index ¶
- Variables
- func NewProxyRequest(method string, queryParameters map[string]string, body interface{}) (*events.APIGatewayProxyRequest, error)
- func NewProxyResponse(statusCode int, contentType ContentType, err error, v interface{}) (*events.APIGatewayProxyResponse, error)
- func UnmarshalAndValidate(request *events.APIGatewayProxyRequest, v Validatable) error
- func UnmarshalDynamoDBEventAttributeValues(attributeValues map[string]events.DynamoDBAttributeValue, v interface{}) error
- type ContentType
- type Validatable
Constants ¶
This section is empty.
Variables ¶
var (
AccessControlAllowOrigin string
)
Functions ¶
func NewProxyRequest ¶
func NewProxyRequest(method string, queryParameters map[string]string, body interface{}) (*events.APIGatewayProxyRequest, error)
NewProxyRequest is a helper method to build a events.APIGatewayProxyRequest object. You can use this method in tests to mock incoming request payloads to a Lambda function.
func NewProxyResponse ¶
func NewProxyResponse(statusCode int, contentType ContentType, err error, v interface{}) (*events.APIGatewayProxyResponse, error)
NewProxyResponse builds an API gateway proxy response using the passed parameters. statusCode should be a valid HTTP status code. If contentType is ContentTypeApplicationJSON v should be a struct that is able to be marshaled into JSON. If contentType is ContentTypeTextHTML v should be a string or byte slice. If err is nil no error will be returned. If the content type is empty/unsupported or v is nil nothing will be written to the response body.
func UnmarshalAndValidate ¶
func UnmarshalAndValidate(request *events.APIGatewayProxyRequest, v Validatable) error
UnmarshalAndValidate unmarshals the request's body into v and then calls Validate on it. v must be a pointer to an object and cannot be nil.
func UnmarshalDynamoDBEventAttributeValues ¶
func UnmarshalDynamoDBEventAttributeValues(attributeValues map[string]events.DynamoDBAttributeValue, v interface{}) error
UnmarshalDynamoDBEventAttributeValues unmarshals attributeValues into v. For v to work with attributevalue.UnmarshalMap it must be a non-nil reference to a struct.
CAUTION: If one of the types of the v interface{} parameter contains a slice of interfaces where an item is of type int it will be converted into a float64. I believe this is either a bug or limitation of the Go reflect package rather than an AWS packages. I haven't look into it enough to be sure though.
This helper function is required because the Lambda events package uses different types to the DynamoDB package. This became even more of a pain the the v2 of the Go AWS SDK. See the following for more information. https://github.com/aws/aws-lambda-go/issues/58 https://github.com/aws/aws-sdk-go-v2/issues/1124
Types ¶
type ContentType ¶
type ContentType string
const ( ContentTypeApplicationJSON ContentType = "application/json" ContentTypeTextHTML ContentType = "text/html" )
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable is an interface for an object that can be validated.