Documentation ¶
Index ¶
- Constants
- func CompressResponse(c *Context) error
- func CompressResponseWithMinimumSize(c *Context, minimum int) error
- func Start(handler func(*Context) error)
- type Context
- func (c *Context) AddResponseHeader(key, value string) *Context
- func (c *Context) Context() context.Context
- func (c *Context) Method() string
- func (c *Context) Metrics() metrics.Metrics
- func (c *Context) ParseIfMatchHeader() (*IfMatch, error)
- func (c *Context) Path() string
- func (c *Context) PathParam(key string) string
- func (c *Context) ProxyS3(client *s3.Client, bucket, key string) error
- func (c *Context) QueryParam(key string) string
- func (c *Context) QueryParamValues(key string) []string
- func (c *Context) Request() *events.APIGatewayV2HTTPRequest
- func (c *Context) RequestHeader(key string) string
- func (c *Context) RequestTimestamp() time.Time
- func (c *Context) Respond(statusCode int) error
- func (c *Context) RespondBadRequest(layout string, v ...interface{}) error
- func (c *Context) RespondFormatted(statusCode int, layout string, v ...interface{}) error
- func (c *Context) RespondInternalServerError() error
- func (c *Context) RespondMessage(statusCode int, message string) error
- func (c *Context) RespondMethodNotAllowed(allow string) error
- func (c *Context) RespondNotFound() error
- func (c *Context) RespondOKWithBase64Data(data []byte) error
- func (c *Context) RespondOKWithJSON(v interface{}) error
- func (c *Context) RespondOKWithText(body string) error
- func (c *Context) Response() *events.APIGatewayV2HTTPResponse
- func (c *Context) SetCacheControlMaxAge(duration time.Duration) *Context
- func (c *Context) SetResponseCachingHeaders(v WithResponseCachingHeaders)
- func (c *Context) SetResponseHeader(key, value string) *Context
- func (c *Context) SetStatusCode(statusCode int) *Context
- func (c *Context) StageVariable(key string) string
- func (c *Context) StageVariables(key string, value *string) *StageVarGetter
- func (c *Context) StatusCode() int
- func (c *Context) UnmarshalRequestBody(v interface{}) error
- func (c *Context) Value(key any) any
- func (c *Context) WithValue(key, value any) context.Context
- type ETag
- type IfMatch
- type StageVarGetter
- type WithResponseCachingHeaders
Constants ¶
const CompressMinimumSizeInBytes = 1024
Variables ¶
This section is empty.
Functions ¶
func CompressResponse ¶
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 ¶
AddResponseHeader is used to add to a response header.
func (*Context) ParseIfMatchHeader ¶
ParseIfMatchHeader parses and returns the If-Match request header.
func (*Context) ProxyS3 ¶
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 ¶
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 ¶
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 ¶
RequestHeader returns the request header for the specified key.
func (*Context) RequestTimestamp ¶
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 ¶
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 ¶
RespondBadRequest is a variant of RespondFormatted for http.StatusBadRequest.
func (*Context) RespondFormatted ¶
RespondFormatted is a variant of RespondMessage that allows formatting of the custom JSON response "message".
func (*Context) RespondInternalServerError ¶
RespondInternalServerError is a variant of Respond for http.StatusBadRequest.
func (*Context) RespondMessage ¶
RespondMessage is a variant of Respond that allows an additional custom JSON response "message" attribute in addition to "status" and "type".
func (*Context) RespondMethodNotAllowed ¶
RespondMethodNotAllowed is a variant of Respond for http.StatusMethodNotAllowed with the Allow header value.
func (*Context) RespondNotFound ¶
RespondNotFound is a variant of Respond for http.StatusNotFound.
func (*Context) RespondOKWithBase64Data ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetResponseHeader is used to modify a response header.
func (*Context) SetStatusCode ¶
SetStatusCode changes the current response's status code.
func (*Context) StageVariable ¶
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 ¶
StatusCode returns the current response's status code .
func (*Context) UnmarshalRequestBody ¶
UnmarshalRequestBody returns the request body as JSON.
type ETag ¶
ETag header value.
func NewStrongETag ¶
NewStrongETag returns an ETag with ETag.Weak set to false.
func NewWeakETag ¶
NewWeakETag returns an ETag with ETag.Weak set to true.
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 ¶
WithResponseCachingHeaders allows implement types to generate ETag and Last-Modified response headers for caching purposes.