proxy

package
v0.0.0-...-e6b3236 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2019 License: MIT Imports: 2 Imported by: 0

README

Proxy

This module will provide a valid response for your AWS Lambda, ready to pass to the API Gateway.

Example

assert.Equal is only used as a helper for the reader

import (
	"github.com/brugnara/lambda-utils/proxy"
)

// simple body:
body := "body"

// json? No problems
js, _ := json.Marshal(yourObject)
body := string(js)

// simple
response := NewResponse(nil, body)
assert.Equal(response.StatusCode, http.StatusOK, ":(") // 500
assert.Equal(response.Body, body, ":(")

// with CORS Header
response := NewResponse(nil, body, true)
assert.Equal(response.StatusCode, http.StatusOK, ":(") // 500
assert.Equal(response.Headers["Access-Control-Allow-Origin"], "*", ":(")
assert.Equal(response.Body, body, ":(")

// handle errors
response := NewResponse(errors.New("A generic error"), body)
assert.Equal(response.StatusCode, http.StatusInternalServerError, ":(") // 500
assert.Equal(response.Body, body, ":(")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResponse

func NewResponse(
	err error,
	body string,
	cors ...bool,
) events.APIGatewayProxyResponse

NewResponse returns a valid APIGatewayProxyResponse object.

Types

This section is empty.

Jump to

Keyboard shortcuts

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