apigatewayproxyresponder

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 4 Imported by: 0

README

apigatewayproxyresponder

utilities for returning responses from a Lambda for API Gateway

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHeaders

func MakeHeaders(overrides ...map[string]string) (ret map[string]string)

MakeHeaders returns the headers for any response.

Every succesful response must retrurn at least these headers: - Content-Type (default: "application/json") - Access-Control-Allow-Origin (default: "*") - Access-Control-Allow-Credentials (default: "true")

For a normal success response, simply call xcr.RespHeaders():

return events.APIGatewayProxyResponse{
	Body:       string(bytes),
		Headers:    xcr.RespHeaders(),
		StatusCode: http.StatusCreated}, nil

To return plain text instead of json, override the Content-Type header:

return events.APIGatewayProxyResponse{
	Body:       fmt.Sprintf("Hello from Stream. %s", time.Now().String()),
	Headers:    MakeHeaders(map[string]string{"Content-Type": "text"}),
	StatusCode: 200}, nil

Types

type Responder

type Responder struct {
	// contains filtered or unexported fields
}

func New

func New(headers http.Header) (Responder, error)

func (*Responder) Respond

func (r *Responder) Respond(code int, body interface{}) (events.APIGatewayProxyResponse, error)

Jump to

Keyboard shortcuts

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