core

package
v0.0.0-...-272c652 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package adapter provides utility methods that help convert events into an http.Request and http.ResponseWriter The code below is adapted from https://github.com/awslabs/aws-lambda-go-api-proxy/blob/19825165bd2fce09ee70ddbd1d4a9a1f710d64a4/core/request.go

Package adapter provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter Adapted for ALB from https://github.com/awslabs/aws-lambda-go-api-proxy/blob/19825165bd2fce09ee70ddbd1d4a9a1f710d64a4/core/response.go

Index

Constants

View Source
const CustomHostVariable = "GO_API_HOST"

CustomHostVariable is the name of the environment variable that contains the custom hostname for the request. If this variable is not set the framework reverts to `DefaultServerAddress`. The value for a custom host should include a protocol: http://my-custom.host.com

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 GetALBContextFromContext

func GetALBContextFromContext(ctx context.Context) (events.ALBTargetGroupRequestContext, bool)

GetALBContextFromContext retrieve ALBTargetGroupRequestContext from context.Context

func GetRuntimeContextFromContext

func GetRuntimeContextFromContext(ctx context.Context) (*lambdacontext.LambdaContext, bool)

GetRuntimeContextFromContext retrieve Lambda Runtime Context from context.Context

func NewLoggedError

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

NewLoggedError generates a new error and logs it to stdout

func TimeoutResponse

func TimeoutResponse() events.ALBTargetGroupResponse

TimeoutResponse returns a dafault Gateway Timeout (504) response

Types

type ProxyResponseWriter

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

ProxyResponseWriter implements http.ResponseWriter and adds the method necessary to return an events.ALBTargetGroupResponse 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.ALBTargetGroupResponse, error)

GetProxyResponse converts the data passed to the response writer into an events.ALBTargetGroupResponse object. Returns a populated proxy response object. If the response 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 {
	// contains filtered or unexported fields
}

RequestAccessor objects give access to custom ALB properties in the request.

func (*RequestAccessor) EventToRequest

func (r *RequestAccessor) EventToRequest(req events.ALBTargetGroupRequest) (*http.Request, error)

EventToRequest converts an ALB event into an http.Request object. Returns the populated request maintaining headers

func (*RequestAccessor) EventToRequestWithContext

func (r *RequestAccessor) EventToRequestWithContext(ctx context.Context, req events.ALBTargetGroupRequest) (*http.Request, error)

EventToRequestWithContext converts an ALB event and context into an http.Request object. Returns the populated http request with lambda context, stage variables and ALBTargetGroupRequestContext as part of its context. Access those using GetALBContextFromContext and GetRuntimeContextFromContext functions in this package.

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. TODO check if this is still needed.

Jump to

Keyboard shortcuts

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