{"modulePath":"github.com/jamillosantos/lambda","version":"v0.0.0-20241128203319-d96fe47cac13","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package http\n\n## Variables\n\n```go\nvar DefaultErrorHandler = func(_ context.Context, err error) (HttpResponse, error) {\n\te := err\n\tfor {\n\t\tif httpErr, ok := e.(ErrorResponse); ok {\n\t\t\tb, err := httpErr.HttpBody()\n\t\t\tif err != nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn HttpResponse{\n\t\t\t\tStatusCode: httpErr.HttpStatusCode(),\n\t\t\t\tHeaders:    httpErr.HttpHeaders(),\n\t\t\t\tBody:       b,\n\t\t\t}, nil\n\t\t}\n\t\tif e = errors.Unwrap(e); e == nil {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn HttpResponse{\n\t\tStatusCode: http.StatusInternalServerError,\n\t\tBody:       []byte(`{\"message\":\"Internal Server Error\"}`),\n\t}, nil\n}\n```\nDefaultErrorHandler is the default error handler for the lambda function. If th error implements ErrorResponse, it will return an HttpResponse with the status code, headers and body. If the error does not implement ErrorResponse, it will return a generic internal server error message.\n\nThe original error message is not returned to avoid accidentally leaking sensitive information.\n\n```go\nvar (\n\tErrKeyNotFound = errors.New(\"key not found\")\n)\n```\n\n## Functions\n\n```go\nfunc StartV1[Req any, Resp any](handler Handler[Req, Resp], opts ...HttpOption)\n```\nStartV1 will start the lambda function with the given handler and options.\n\nThe handler is a function that receives a context and a pointer to a Context.\n\n```go\nfunc StartV2[Req any, Resp any](handler Handler[Req, Resp], opts ...HttpOption)\n```\nStartV2 will start the lambda function with the given handler and options.\n\nThe handler is a function that receives a context and a pointer to a Context.\n\n## Types\n\n```go\ntype APIGatewayProxyRequest struct {\n\tResource                        string                               `json:\"resource\"` // The resource path defined in API Gateway\n\tPath                            string                               `json:\"path\"`     // The url path for the caller\n\tHTTPMethod                      string                               `json:\"httpMethod\"`\n\tHeaders                         map[string]string                    `json:\"headers\"`\n\tMultiValueHeaders               map[string][]string                  `json:\"multiValueHeaders\"`\n\tQueryStringParameters           map[string]string                    `json:\"queryStringParameters\"`\n\tMultiValueQueryStringParameters map[string][]string                  `json:\"multiValueQueryStringParameters\"`\n\tPathParameters                  map[string]string                    `json:\"pathParameters\"`\n\tStageVariables                  map[string]string                    `json:\"stageVariables\"`\n\tRequestContext                  events.APIGatewayProxyRequestContext `json:\"requestContext\"`\n\tBody                            string                               `json:\"body\"`\n\tIsBase64Encoded                 bool                                 `json:\"isBase64Encoded,omitempty\"`\n}\n```\nAPIGatewayProxyRequest contains data coming from the API Gateway proxy\n\n```go\ntype APIGatewayProxyResponse struct {\n\tStatusCode int               `json:\"statusCode\"`\n\tHeaders    map[string]string `json:\"headers\"`\n\tBody       json.RawMessage   `json:\"body\"`\n}\n```\nAPIGatewayProxyResponse configures the response to be returned by API Gateway for the request\n\n```go\ntype APIGatewayV2HTTPResponse struct {\n\tStatusCode        int                 `json:\"statusCode\"`\n\tHeaders           map[string]string   `json:\"headers\"`\n\tMultiValueHeaders map[string][]string `json:\"multiValueHeaders\"`\n\tBody              string              `json:\"body\"`\n\tIsBase64Encoded   bool                `json:\"isBase64Encoded,omitempty\"`\n\tCookies           []string            `json:\"cookies\"`\n}\n```\n\n```go\ntype Context[Req any, Resp any] struct {\n\tContext  context.Context\n\tRequest  *Request[Req]\n\tResponse *Response[Resp]\n\tLocals   map[string]any\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (l *Context[Req, Resp]) Error() string\n```\n\n```go\nfunc (l *Context[Req, Resp]) GetLocal(key string) (any, bool)\n```\n\n```go\nfunc (l *Context[Req, Resp]) Is(err error) bool\n```\n\n```go\nfunc (l *Context[Req, Resp]) SetLocal(key string, value any) *Context[Req, Resp]\n```\n\n```go\nfunc (l *Context[Req, Resp]) UnsetLocal(key string) *Context[Req, Resp]\n```\n\n```go\ntype Cookie struct {\n\tName        string\n\tValue       string\n\tPath        string\n\tDomain      string\n\tMaxAge      int\n\tExpires     time.Time\n\tSecure      bool\n\tHTTPOnly    bool\n\tSameSite    CookieSameSite\n\tSessionOnly bool\n}\n```\n\n```go\nfunc (c *Cookie) String() string\n```\n\n```go\ntype CookieSameSite string\n```\n\n```go\nconst (\n\tCookieSameSiteDefaultMode CookieSameSite = \"SameSite\"\n\tCookieSameSiteLaxMode     CookieSameSite = \"Lax\"\n\tCookieSameSiteStrictMode  CookieSameSite = \"Strict\"\n\tCookieSameSiteNoneMode    CookieSameSite = \"None\"\n)\n```\n\n```go\ntype Error struct {\n\tStatusCode int\n\tHeaders    map[string]string\n\tMessage    string\n}\n```\nError is a struct that implements ErrorResponse. It represents an error that can be returned by the lambda function.\n\n```go\nfunc (h *Error) Error() string\n```\n\n```go\nfunc (h *Error) HttpBody() (json.RawMessage, error)\n```\n\n```go\nfunc (h *Error) HttpHeaders() map[string]string\n```\n\n```go\nfunc (h *Error) HttpStatusCode() int\n```\n\n```go\ntype ErrorResponse interface {\n\tHttpStatusCode() int\n\tHttpHeaders() map[string]string\n\tHttpBody() (json.RawMessage, error)\n}\n```\n\n```go\ntype Handler[Req any, Resp any] func(*Context[Req, Resp]) error\n```\n\n```go\nfunc Use[Req any, Resp any](handler Handler[Req, Resp], middlewares ...Middleware[Req, Resp]) Handler[Req, Resp]\n```\n\n```go\ntype Headers = mapUtils\n```\n\n```go\ntype HttpOption func(*options)\n```\n\n```go\nfunc WithErrorHandler(h func(context.Context, error) (HttpResponse, error)) HttpOption\n```\nWithErrorHandler is an option that allows you to pass a custom error handler to the lambda function.\n\n```go\nfunc WithResources(r ...Resource) HttpOption\n```\nWithResources is an option that allows you to pass resources to the lambda function.\n\n```go\ntype HttpResponse struct {\n\tStatusCode int\n\tHeaders    map[string]string\n\tBody       json.RawMessage\n}\n```\n\n```go\ntype Middleware[Req any, Resp any] func(ctx *Context[Req, Resp], next Handler[Req, Resp]) error\n```\n\n```go\ntype None struct{}\n```\n\n```go\ntype PathParams map[string]string\n```\n\n```go\nfunc (p PathParams) Bool(key string) (bool, error)\n```\n\n```go\nfunc (p PathParams) Float64(key string) (float64, error)\n```\n\n```go\nfunc (p PathParams) Int(key string) (int, error)\n```\n\n```go\nfunc (p PathParams) Int64(key string) (int64, error)\n```\n\n```go\nfunc (p PathParams) String(key string) (string, bool)\n```\n\n```go\ntype Query = mapUtils\n```\n\n```go\ntype Request[T any] struct {\n\tHTTPMethod string\n\tPath       string\n\tPathParams PathParams\n\tQuery      Query\n\tHeaders    Headers\n\n\tBody T\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (r *Request[T]) Cookie(key string) (string, bool)\n```\n\n```go\ntype Resource interface {\n\tName() string\n\tStart(context.Context) error\n}\n```\n\n```go\ntype Response[T any] struct {\n\tStatusCode int\n\tHeaders    map[string]string\n\tCookies    []Cookie\n\tBody       bytes.Buffer\n\tErr        error\n}\n```\n\n```go\nfunc (r *Response[T]) Error() string\n```\n\n```go\nfunc (r *Response[T]) Header(key string, value string) *Response[T]\n```\n\n```go\nfunc (r *Response[T]) JSON(data any) *Response[T]\n```\n\n```go\nfunc (r *Response[T]) Redirect(url string, status ...int) *Response[T]\n```\n\n```go\nfunc (r *Response[T]) SendString(data string) *Response[T]\n```\n\n```go\nfunc (r *Response[T]) SetCookie(c Cookie) *Response[T]\n```\n\n```go\nfunc (r *Response[T]) Status(status int) *Response[T]\n```\n\n```go\nfunc (r *Response[T]) UnsetCookie(name string) *Response[T]\n```\n\n","path":"github.com/jamillosantos/lambda/http","name":"http","synopsis":"","isRedistributable":true}
