lambda

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AWSRequestToHTTPRequest

func AWSRequestToHTTPRequest(ctx context.Context, event Request) (*http.Request, error)

Types

type HandlerFunc

type HandlerFunc func(
	ctx context.Context, event Request,
) (Response, error)

HandlerFunc is a generic HandlerFunc for incoming http requests/events incoming request will be run through http server which will return the response.

func Handler

func Handler(handler http.Handler, logger *slog.Logger) HandlerFunc

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) CloseNotify

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

func (*ProxyResponseWriter) GetLambdaResponse

func (r *ProxyResponseWriter) GetLambdaResponse() (Response, error)

GetLambdaResponse converts the data passed to the response writer into an Response object. Returns a populated lambda 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 Request

type Request struct {
	events.ALBTargetGroupRequest
	events.APIGatewayV2HTTPRequest //nolint:govet

	// Added to resolve "ambiguous selectors" error
	Headers               map[string]string `json:"headers"`
	QueryStringParameters map[string]string `json:"queryStringParameters"`
	RequestContext        RequestContext    `json:"requestContext"`
	Body                  string            `json:"body"`
	IsBase64Encoded       bool              `json:"isBase64Encoded"`
}

Request wraps ALBTargetGroupRequest and APIGatewayV2HTTPRequest into a generic request struct.

type Response

type Response struct {
	StatusCode        int                 `json:"statusCode"`
	Headers           map[string]string   `json:"headers"`
	MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
	Body              string              `json:"body"`
	IsBase64Encoded   bool                `json:"isBase64Encoded"`
	Cookies           []string            `json:"cookies"`
}

Request mimics ALBTargetGroupResponse and APIGatewayV2HTTPResponse into a generic response struct.

Jump to

Keyboard shortcuts

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