xlambda

package module
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 8 Imported by: 6

README

A collection of functions, objects and interfaces to help write Lambdas

GitHub tag (latest SemVer pre-release) GitHub go.mod Go version GitHub Workflow Status Go Report Card PkgGoDev

Introduction

  • AWS SDK Go v2 support

Testing

Run go test ./... at the root of the project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize added in v0.5.0

func Initialize(_accessControlAllowOrigin string) error

func ParseAndValidate added in v0.6.0

func ParseAndValidate(request *events.APIGatewayProxyRequest, validatable Validatable) error

ParseAndValidate unmarshals the query string parameters into validatable and then calls Validate on it. validatable must be a pointer to an object and cannot be nil.

func ProxyRequest added in v0.6.0

func ProxyRequest(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 ProxyResponseHTML added in v0.5.0

func ProxyResponseHTML(statusCode int, err error, data interface{}) (*events.APIGatewayProxyResponse, error)

ProxyResponseHTML builds an API gateway proxy response where the body's content type is text/html. statusCode should be a valid HTTP status code. If err is nil no error will be returned. If data is nil nothing will be written to the response body.

func ProxyResponseJSON added in v0.5.0

func ProxyResponseJSON(statusCode int, err error, data interface{}) (*events.APIGatewayProxyResponse, error)

ProxyResponseJSON builds an API gateway proxy response where the body's content type is application/json. statusCode should be a valid HTTP status code. If err is nil no error will be returned. If data is nil nothing will be written to the response body.

func UnmarshalAndValidate

func UnmarshalAndValidate(request *events.APIGatewayProxyRequest, validatable Validatable) error

UnmarshalAndValidate unmarshals the request's body into validatable and then calls Validate on it. validatable 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 Validatable

type Validatable interface {
	Validate() error
}

Validatable is an interface for an object that can be validated.

Jump to

Keyboard shortcuts

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