core

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 15 Imported by: 154

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 ALB 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

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

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

Index

Constants

View Source
const (
	// 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 `RequestContext.DomainName`. The value for a custom host should
	// include a protocol: http://my-custom.host.com
	CustomHostVariable = "GO_API_HOST"

	// 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.
	APIGwContextHeader = "X-GoLambdaProxy-ApiGw-Context"

	// 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.
	APIGwStageVarsHeader = "X-GoLambdaProxy-ApiGw-StageVars"
)
View Source
const (
	// ALBContextHeader is the custom header key used to store the
	// ALB ELB context. To access the Context properties use the
	// GetALBContext method of the RequestAccessorALB object.
	ALBContextHeader = "X-GoLambdaProxy-ALB-Context"
)

Variables

This section is empty.

Functions

func GatewayTimeout

func GatewayTimeout() events.APIGatewayProxyResponse

GatewayTimeout returns a dafault Gateway Timeout (504) response

func GatewayTimeoutALB added in v0.14.0

func GatewayTimeoutALB() events.ALBTargetGroupResponse

func GatewayTimeoutV2 added in v0.10.0

func GatewayTimeoutV2() events.APIGatewayV2HTTPResponse

func GetAPIGatewayContextFromContext added in v0.3.0

func GetAPIGatewayContextFromContext(ctx context.Context) (events.APIGatewayProxyRequestContext, bool)

GetAPIGatewayContextFromContext retrieve APIGatewayProxyRequestContext from context.Context

func GetAPIGatewayV2ContextFromContext added in v0.10.0

func GetAPIGatewayV2ContextFromContext(ctx context.Context) (events.APIGatewayV2HTTPRequestContext, bool)

GetAPIGatewayV2ContextFromContext retrieve APIGatewayProxyRequestContext from context.Context

func GetRuntimeContextFromContext added in v0.3.0

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

GetRuntimeContextFromContext retrieve Lambda Runtime Context from context.Context

func GetRuntimeContextFromContextALB added in v0.14.0

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

GetRuntimeContextFromContext retrieve Lambda Runtime Context from context.Context

func GetRuntimeContextFromContextV2 added in v0.10.0

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

GetRuntimeContextFromContextV2 retrieve Lambda Runtime Context from context.Context

func GetStageVarsFromContext added in v0.3.0

func GetStageVarsFromContext(ctx context.Context) (map[string]string, bool)

GetStageVarsFromContext retrieve stage variables from context

func GetStageVarsFromContextV2 added in v0.10.0

func GetStageVarsFromContextV2(ctx context.Context) (map[string]string, bool)

GetStageVarsFromContextV2 retrieve stage variables from context

func GetTargetGroupRequetFromContextALB added in v0.14.0

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

GetALBTargetGroupRequestFromContext retrieve ALBTargetGroupt from context.Context

func NewLoggedError

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

NewLoggedError generates a new error and logs it to stdout

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) CloseNotify added in v0.5.0

func (r *ProxyResponseWriter) CloseNotify() <-chan bool

func (*ProxyResponseWriter) Flush added in v0.16.0

func (r *ProxyResponseWriter) Flush()

Flush implements the Flusher interface which is called by some implementers. This is intentionally a no-op

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 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 ProxyResponseWriterALB added in v0.14.0

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

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

func NewProxyResponseWriterALB added in v0.14.0

func NewProxyResponseWriterALB() *ProxyResponseWriterALB

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

func (*ProxyResponseWriterALB) CloseNotify added in v0.14.0

func (r *ProxyResponseWriterALB) CloseNotify() <-chan bool

func (*ProxyResponseWriterALB) GetProxyResponse added in v0.14.0

func (r *ProxyResponseWriterALB) 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 (*ProxyResponseWriterALB) Header added in v0.14.0

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

Header implementation from the http.ResponseWriter interface.

func (*ProxyResponseWriterALB) Write added in v0.14.0

func (r *ProxyResponseWriterALB) 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 (*ProxyResponseWriterALB) WriteHeader added in v0.14.0

func (r *ProxyResponseWriterALB) WriteHeader(status int)

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

type ProxyResponseWriterV2 added in v0.10.0

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

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

func NewProxyResponseWriterV2 added in v0.10.0

func NewProxyResponseWriterV2() *ProxyResponseWriterV2

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

func (*ProxyResponseWriterV2) CloseNotify added in v0.10.0

func (r *ProxyResponseWriterV2) CloseNotify() <-chan bool

func (*ProxyResponseWriterV2) GetProxyResponse added in v0.10.0

GetProxyResponse converts the data passed to the response writer into an events.APIGatewayProxyResponse 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 (*ProxyResponseWriterV2) Header added in v0.10.0

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

Header implementation from the http.ResponseWriter interface.

func (*ProxyResponseWriterV2) Write added in v0.10.0

func (r *ProxyResponseWriterV2) 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 (*ProxyResponseWriterV2) WriteHeader added in v0.10.0

func (r *ProxyResponseWriterV2) 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 API Gateway properties in the request.

func (*RequestAccessor) EventToRequest added in v0.3.0

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

EventToRequest converts an API Gateway proxy event into an http.Request object. Returns the populated request maintaining headers

func (*RequestAccessor) EventToRequestWithContext added in v0.3.0

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

EventToRequestWithContext converts an API Gateway proxy event and context into an http.Request object. Returns the populated http request with lambda context, stage variables and APIGatewayProxyRequestContext as part of its context. Access those using GetAPIGatewayContextFromContext, GetStageVarsFromContext and GetRuntimeContextFromContext functions in this package.

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 a http.Request object. Returns the populated http request with 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.

type RequestAccessorALB added in v0.14.0

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

RequestAccessorALB objects give access to custom ALB Target Group properties in the request.

func (*RequestAccessorALB) EventToRequest added in v0.14.0

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

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

func (*RequestAccessorALB) EventToRequestWithContext added in v0.14.0

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

EventToRequestWithContext converts an ALB Target Group Request event and context into an http.Request object. Returns the populated http request with lambda context, ALB TargetGroup RequestContext as part of its context.

func (*RequestAccessorALB) GetContextALB added in v0.14.0

GetALBContext extracts the ALB context object from a request's custom header. Returns a populated events.ALBTargetGroupRequestContext object from the request.

func (*RequestAccessorALB) ProxyEventToHTTPRequest added in v0.14.0

func (r *RequestAccessorALB) ProxyEventToHTTPRequest(req events.ALBTargetGroupRequest) (*http.Request, error)

ProxyEventToHTTPRequest converts an ALB Target Group Request event into a http.Request object. Returns the populated http request with additional custom header for the ALB context. To access these properties use the GetALBContext method of the RequestAccessorALB object.

func (*RequestAccessorALB) StripBasePath added in v0.14.0

func (r *RequestAccessorALB) 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.

type RequestAccessorV2 added in v0.10.0

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

RequestAccessorV2 objects give access to custom API Gateway properties in the request.

func (*RequestAccessorV2) EventToRequest added in v0.10.0

EventToRequest converts an API Gateway proxy event into an http.Request object. Returns the populated request maintaining headers

func (*RequestAccessorV2) EventToRequestWithContext added in v0.10.0

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

EventToRequestWithContext converts an API Gateway proxy event and context into an http.Request object. Returns the populated http request with lambda context, stage variables and APIGatewayProxyRequestContext as part of its context. Access those using GetAPIGatewayContextFromContext, GetStageVarsFromContext and GetRuntimeContextFromContext functions in this package.

func (*RequestAccessorV2) GetAPIGatewayContextV2 added in v0.10.0

func (r *RequestAccessorV2) GetAPIGatewayContextV2(req *http.Request) (events.APIGatewayV2HTTPRequestContext, error)

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

func (*RequestAccessorV2) GetAPIGatewayStageVars added in v0.10.0

func (r *RequestAccessorV2) 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 (*RequestAccessorV2) ProxyEventToHTTPRequest added in v0.10.0

func (r *RequestAccessorV2) ProxyEventToHTTPRequest(req events.APIGatewayV2HTTPRequest) (*http.Request, error)

ProxyEventToHTTPRequest converts an API Gateway proxy event into a http.Request object. Returns the populated http request with 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 (*RequestAccessorV2) StripBasePath added in v0.10.0

func (r *RequestAccessorV2) 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.

type SwitchableAPIGatewayRequest added in v0.13.0

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

func NewSwitchableAPIGatewayRequestV1 added in v0.13.0

func NewSwitchableAPIGatewayRequestV1(v *events.APIGatewayProxyRequest) *SwitchableAPIGatewayRequest

NewSwitchableAPIGatewayRequestV1 creates a new SwitchableAPIGatewayRequest from APIGatewayProxyRequest

func NewSwitchableAPIGatewayRequestV2 added in v0.13.0

func NewSwitchableAPIGatewayRequestV2(v *events.APIGatewayV2HTTPRequest) *SwitchableAPIGatewayRequest

NewSwitchableAPIGatewayRequestV2 creates a new SwitchableAPIGatewayRequest from APIGatewayV2HTTPRequest

func (*SwitchableAPIGatewayRequest) MarshalJSON added in v0.13.0

func (s *SwitchableAPIGatewayRequest) MarshalJSON() ([]byte, error)

MarshalJSON is a pass through serialization

func (*SwitchableAPIGatewayRequest) UnmarshalJSON added in v0.13.0

func (s *SwitchableAPIGatewayRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON is a switching serialization based on the presence of fields in the source JSON, multiValueQueryStringParameters for APIGatewayProxyRequest and rawQueryString for APIGatewayV2HTTPRequest.

func (*SwitchableAPIGatewayRequest) Version1 added in v0.13.0

Version1 returns the contained events.APIGatewayProxyRequest or nil

func (*SwitchableAPIGatewayRequest) Version2 added in v0.13.0

Version2 returns the contained events.APIGatewayV2HTTPRequest or nil

type SwitchableAPIGatewayResponse added in v0.13.0

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

SwitchableAPIGatewayResponse is a container for an APIGatewayProxyResponse or an APIGatewayV2HTTPResponse object which handles serialization and deserialization and switching between the entities based on the presence of fields in the source JSON, multiValueQueryStringParameters for APIGatewayProxyResponse and rawQueryString for APIGatewayV2HTTPResponse. It also provides some simple switching functions (wrapped type switching.)

func NewSwitchableAPIGatewayResponseV1 added in v0.13.0

func NewSwitchableAPIGatewayResponseV1(v *events.APIGatewayProxyResponse) *SwitchableAPIGatewayResponse

NewSwitchableAPIGatewayResponseV1 creates a new SwitchableAPIGatewayResponse from APIGatewayProxyResponse

func NewSwitchableAPIGatewayResponseV2 added in v0.13.0

func NewSwitchableAPIGatewayResponseV2(v *events.APIGatewayV2HTTPResponse) *SwitchableAPIGatewayResponse

NewSwitchableAPIGatewayResponseV2 creates a new SwitchableAPIGatewayResponse from APIGatewayV2HTTPResponse

func (*SwitchableAPIGatewayResponse) MarshalJSON added in v0.13.0

func (s *SwitchableAPIGatewayResponse) MarshalJSON() ([]byte, error)

MarshalJSON is a pass through serialization

func (*SwitchableAPIGatewayResponse) UnmarshalJSON added in v0.13.0

func (s *SwitchableAPIGatewayResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON is a switching serialization based on the presence of fields in the source JSON, statusCode to verify that it's either APIGatewayProxyResponse or APIGatewayV2HTTPResponse and then rawQueryString for to determine if it is APIGatewayV2HTTPResponse or not.

func (*SwitchableAPIGatewayResponse) Version1 added in v0.13.0

Version1 returns the contained events.APIGatewayProxyResponse or nil

func (*SwitchableAPIGatewayResponse) Version2 added in v0.13.0

Version2 returns the contained events.APIGatewayV2HTTPResponse or nil

Jump to

Keyboard shortcuts

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