framework

package
v0.0.0-...-3a9ac50 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CompressMinimumSizeInBytes = 1024

Variables

This section is empty.

Functions

func CompressResponse

func CompressResponse(c *Context) error

func CompressResponseWithMinimumSize

func CompressResponseWithMinimumSize(c *Context, minimum int) error

func Start

func Start(handler func(*Context) error)

Start starts the Lambda runtime loop.

Types

type Context

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

Context contains the original context from Lambda and methods to read attributes of the original events.APIGatewayV2HTTPRequest and write to the events.APIGatewayV2HTTPResponse.

func (*Context) AddResponseHeader

func (c *Context) AddResponseHeader(key, value string) *Context

AddResponseHeader is used to add to a response header.

func (*Context) Context

func (c *Context) Context() context.Context

Context returns the original context.Context of the request.

func (*Context) Method

func (c *Context) Method() string

Method returns the HTTP method of the request.

func (*Context) Metrics

func (c *Context) Metrics() metrics.Metrics

Metrics returns the current metrics.Metrics instance from context.

func (*Context) ParseIfMatchHeader

func (c *Context) ParseIfMatchHeader() (*IfMatch, error)

ParseIfMatchHeader parses and returns the If-Match request header.

func (*Context) Path

func (c *Context) Path() string

Path returns the HTTP path of the request.

func (*Context) PathParam

func (c *Context) PathParam(key string) string

PathParam returns the path parameter value for the specified key.

func (*Context) ProxyS3

func (c *Context) ProxyS3(client *s3.Client, bucket, key string) error

ProxyS3 will call S3 with the appropriate GET or HEAD method and sets the response accordingly. See apigatewayhttpapi.ProxyS3. Please be mindful of the payload limit; this method cannot be used to return files larger than ~6MB.

func (*Context) QueryParam

func (c *Context) QueryParam(key string) string

QueryParam returns the query parameter value for the specified key. If there are multiple values for the same header, QueryParam will return the first. See QueryParamValues.

func (*Context) QueryParamValues

func (c *Context) QueryParamValues(key string) []string

QueryParamValues returns the query parameter values for the specified key. Use this method if there are multiple values for the same header.

func (*Context) Request

func (c *Context) Request() *events.APIGatewayV2HTTPRequest

Request returns the original events.APIGatewayV2HTTPRequest request instance.

func (*Context) RequestHeader

func (c *Context) RequestHeader(key string) string

RequestHeader returns the request header for the specified key.

func (*Context) RequestTimestamp

func (c *Context) RequestTimestamp() time.Time

RequestTimestamp returns the TimeEpoch of events.APIGatewayV2HTTPRequestContext wrapped as time.Time. Check time.Time.IsZero in case the TimeEpoch is missing or 0.

func (*Context) Respond

func (c *Context) Respond(statusCode int) error

Respond sets the response's status code and a generated JSON response that contains the numeric "status" and a string "type" describing that status. Use this method if the status code is self-sufficient, and you don't need any additional message returned to caller.

func (*Context) RespondBadRequest

func (c *Context) RespondBadRequest(layout string, v ...interface{}) error

RespondBadRequest is a variant of RespondFormatted for http.StatusBadRequest.

func (*Context) RespondFormatted

func (c *Context) RespondFormatted(statusCode int, layout string, v ...interface{}) error

RespondFormatted is a variant of RespondMessage that allows formatting of the custom JSON response "message".

func (*Context) RespondInternalServerError

func (c *Context) RespondInternalServerError() error

RespondInternalServerError is a variant of Respond for http.StatusBadRequest.

func (*Context) RespondMessage

func (c *Context) RespondMessage(statusCode int, message string) error

RespondMessage is a variant of Respond that allows an additional custom JSON response "message" attribute in addition to "status" and "type".

func (*Context) RespondMethodNotAllowed

func (c *Context) RespondMethodNotAllowed(allow string) error

RespondMethodNotAllowed is a variant of Respond for http.StatusMethodNotAllowed with the Allow header value.

func (*Context) RespondNotFound

func (c *Context) RespondNotFound() error

RespondNotFound is a variant of Respond for http.StatusNotFound.

func (*Context) RespondOKWithBase64Data

func (c *Context) RespondOKWithBase64Data(data []byte) error

RespondOKWithBase64Data sets the response body to the base64 encoding of the given data. The response's status code is set to http.StatusOK, the response's header "Content-Type" is unchanged.

func (*Context) RespondOKWithJSON

func (c *Context) RespondOKWithJSON(v interface{}) error

RespondOKWithJSON sets the response body to the JSON content of the argument v. If that succeeds, the response's status code is set to http.StatusOK, and the response's header "Content-Type" to "application/json". Use this method if you want to return a generic JSON result with 200 status code.

func (*Context) RespondOKWithText

func (c *Context) RespondOKWithText(body string) error

RespondOKWithText sets the response body to plain-text. The response's status code is set to http.StatusOK, and the response's header "Content-Type" to "text/plain". Use this method if you want to return a generic plain-text result with 200 status code.

func (*Context) Response

func (c *Context) Response() *events.APIGatewayV2HTTPResponse

Response returns the events.APIGatewayV2HTTPResponse instance that will be used to return contents back to caller.

func (*Context) SetCacheControlMaxAge

func (c *Context) SetCacheControlMaxAge(duration time.Duration) *Context

SetCacheControlMaxAge Sets the response Cache-Control header.

func (*Context) SetResponseCachingHeaders

func (c *Context) SetResponseCachingHeaders(v WithResponseCachingHeaders)

SetResponseCachingHeaders adds ETag and Last-Modified headers to the response.

func (*Context) SetResponseHeader

func (c *Context) SetResponseHeader(key, value string) *Context

SetResponseHeader is used to modify a response header.

func (*Context) SetStatusCode

func (c *Context) SetStatusCode(statusCode int) *Context

SetStatusCode changes the current response's status code.

func (*Context) StageVariable

func (c *Context) StageVariable(key string) string

StageVariable returns the stage variable for the specified key.

func (*Context) StageVariables

func (c *Context) StageVariables(key string, value *string) *StageVarGetter

Retrieves several stage variables, if any are missing then the StageVarGetter.Error() will return non-nil.

func (*Context) StatusCode

func (c *Context) StatusCode() int

StatusCode returns the current response's status code .

func (*Context) UnmarshalRequestBody

func (c *Context) UnmarshalRequestBody(v interface{}) error

UnmarshalRequestBody returns the request body as JSON.

func (*Context) Value

func (c *Context) Value(key any) any

Value returns the value associated with the underlying Context that has been added with WithValue.

func (*Context) WithValue

func (c *Context) WithValue(key, value any) context.Context

WithValue replaces the underlying Context with the result from calling context.WithValue.

type ETag

type ETag struct {
	Value string
	Weak  bool
}

ETag header value.

func NewStrongETag

func NewStrongETag(value string) ETag

NewStrongETag returns an ETag with ETag.Weak set to false.

func NewWeakETag

func NewWeakETag(value string) ETag

NewWeakETag returns an ETag with ETag.Weak set to true.

func (ETag) String

func (e ETag) String() string

String implements the fmt.Stringer interface. If ETag.Weak is true, the prefix "W/" will be added.

type IfMatch

type IfMatch struct {
	ETags []ETag
	Any   bool
}

IfMatch header value.

type StageVarGetter

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

func (StageVarGetter) Error

func (g StageVarGetter) Error() error

func (*StageVarGetter) Get

func (g *StageVarGetter) Get(key string, value *string) *StageVarGetter

type WithResponseCachingHeaders

type WithResponseCachingHeaders interface {
	ETag() *ETag
	LastModified() *time.Time
}

WithResponseCachingHeaders allows implement types to generate ETag and Last-Modified response headers for caching purposes.

Jump to

Keyboard shortcuts

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