core

package
v0.0.0-...-0edfd9e Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package core provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter

Package core provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter

Index

Constants

View Source
const APIGwContextHeader = "X-GoLambdaProxy-ApiGw-Context"

APIGwContextHeader is the custom header key used to store the API Gateway context. To access the Context properties use the GetAPIGatewayContext method of the RequestAccessor object.

View Source
const APIGwStageVarsHeader = "X-GoLambdaProxy-ApiGw-StageVars"

APIGwStageVarsHeader is the custom header key used to store the API Gateway stage variables. To access the stage variable values use the GetAPIGatewayStageVars method of the RequestAccessor object.

View Source
const DefaultServerAddress = "https://aws-serverless-go-api.com"

DefaultServerAddress is prepended to the path of each incoming reuqest

Variables

This section is empty.

Functions

func GatewayTimeout

func GatewayTimeout() events.APIGatewayProxyResponse

GatewayTimeout returns a dafault Gateway Timeout (504) response

func NewLoggedError

func NewLoggedError(format string, a ...interface{}) error

New Logged Error

Types

type ProxyResponseWriter

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

ProxyResponseWriter implements http.ResponseWriter and adds the method necessary to return an events.APIGatewayProxyResponse object

func NewProxyResponseWriter

func NewProxyResponseWriter() *ProxyResponseWriter

NewProxyResponseWriter returns a new ProxyResponseWriter object. The object is initialized with an empty map of headers and a status code of -1

func (*ProxyResponseWriter) GetProxyResponse

func (r *ProxyResponseWriter) GetProxyResponse() (events.APIGatewayProxyResponse, error)

GetProxyResponse converts the data passed to the response writer into an events.APIGatewayProxyResponse object. Returns a populated proxy response object. If the reponse is invalid, for example has no headers or an invalid status code returns an error.

func (*ProxyResponseWriter) Header

func (r *ProxyResponseWriter) Header() http.Header

Header implementation from the http.ResponseWriter interface.

func (*ProxyResponseWriter) Write

func (r *ProxyResponseWriter) Write(body []byte) (int, error)

Write sets the response body in the object. If no status code was set before with the WriteHeader method it sets the status for the response to 200 OK.

func (*ProxyResponseWriter) WriteHeader

func (r *ProxyResponseWriter) WriteHeader(status int)

WriteHeader sets a status code for the response. This method is used for error responses.

type RequestAccessor

type RequestAccessor struct {
	ServerAddress string
	// contains filtered or unexported fields
}

RequestAccessor objects give access to custom API Gateway properties in the request. ServerAddress should be the full URI of the service.

func (*RequestAccessor) GetAPIGatewayContext

func (r *RequestAccessor) GetAPIGatewayContext(req *http.Request) (events.APIGatewayProxyRequestContext, error)

GetAPIGatewayContext extracts the API Gateway context object from a request's custom header. Returns a populated events.APIGatewayProxyRequestContext object from the request.

func (*RequestAccessor) GetAPIGatewayStageVars

func (r *RequestAccessor) GetAPIGatewayStageVars(req *http.Request) (map[string]string, error)

GetAPIGatewayStageVars extracts the API Gateway stage variables from a request's custom header. Returns a map[string]string of the stage variables and their values from the request.

func (*RequestAccessor) ProxyEventToHTTPRequest

func (r *RequestAccessor) ProxyEventToHTTPRequest(req events.APIGatewayProxyRequest) (*http.Request, error)

ProxyEventToHTTPRequest converts an API Gateway proxy event into an http.Request object. Returns the populated request with an additional two custom headers for the stage variables and API Gateway context. To access these properties use the GetAPIGatewayStageVars and GetAPIGatewayContext method of the RequestAccessor object.

func (*RequestAccessor) StripBasePath

func (r *RequestAccessor) StripBasePath(basePath string) string

StripBasePath instructs the RequestAccessor object that the given base path should be removed from the request path before sending it to the framework for routing. This is used when API Gateway is configured with base path mappings in custom domain names.

Jump to

Keyboard shortcuts

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