{"modulePath":"github.com/asteroid-computing/go-lambda-edge","version":"v0.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package edge\n\nPackage edge adapts AWS API Gateway Lambda proxy events to net/http handlers. It supports raw JSON v2 and already typed AWS events with optional native gateway identity. Buffered and REST streaming responses share request and identity policies; each has its own response and invocation boundary.\n\n## Variables\n\n```go\nvar (\n\t// ErrInvalidInvocation indicates an invalid direct invocation argument or adapter.\n\tErrInvalidInvocation = errors.New(\"edge: invalid invocation\")\n\t// ErrInvalidEvent indicates a malformed event or failed HTTP request conversion.\n\tErrInvalidEvent = errors.New(\"edge: invalid event\")\n\t// ErrUnsupportedEvent indicates an unsupported event family or payload version.\n\tErrUnsupportedEvent = errors.New(\"edge: unsupported event\")\n\t// ErrIdentity indicates failure to establish or isolate invocation identity.\n\tErrIdentity = errors.New(\"edge: identity failure\")\n\t// ErrResponse indicates an invalid or unrepresentable HTTP response.\n\tErrResponse = errors.New(\"edge: response failure\")\n\t// ErrLimitExceeded indicates an adapter-enforced resource limit.\n\tErrLimitExceeded = errors.New(\"edge: resource limit exceeded\")\n\t// ErrCleanup indicates failure to clean up invocation-owned request resources.\n\tErrCleanup = errors.New(\"edge: request cleanup failure\")\n\t// ErrStream indicates a stream lifecycle failure or a recovered late panic.\n\tErrStream = errors.New(\"edge: stream failure\")\n)\n```\nInvocation failure categories support errors.Is through wrapping and joined errors. Application HTTP responses, including 4xx and 5xx, are not invocation failures when the transport completes successfully.\n\n## Types\n\n```go\ntype Adapter struct {\n\t// contains filtered or unexported fields\n}\n```\nAdapter holds an HTTP handler and its API Gateway adaptation configuration. Construct an Adapter with [New](#New); its zero value is not usable. Configuration is fixed at construction. Calls own separate request state; a shared handler must be safe for concurrent use.\n\n```go\nfunc New(handler http.Handler, opts ...Option) (*Adapter, error)\n```\nNew validates handler and opts and returns an Adapter without performing I/O or invoking handler. Nil handlers, including typed nil handlers, and nil options are rejected. On error, the returned Adapter is nil.\n\nThe caller retains ownership of handler and is responsible for its concurrency safety when sharing it. New does not use [http.DefaultServeMux](/net/http#DefaultServeMux).\n\n```go\nfunc (a *Adapter) HandleV1(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)\n```\nHandleV1 adapts an already decoded REST/HTTP API 1.0 event without serializing envelopes inside edge. It can be registered as lambda.Start(adapter.HandleV1). The upstream decoder owns wire validation and numeric fidelity; the caller or runtime owns final response serialization and its complete envelope size. On failure it returns a zero response. Inputs must not change during the call.\n\n```go\nfunc (a *Adapter) HandleV2(ctx context.Context, event events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error)\n```\nHandleV2 adapts an already decoded HTTP API 2.0 event. Its ownership, error and serialization contract matches HandleV1. V2 SDK string claims cannot recover arrays or exact numeric values discarded by an upstream decoder.\n\n```go\nfunc (a *Adapter) Invoke(ctx context.Context, payload []byte) ([]byte, error)\n```\nInvoke adapts a REST proxy, HTTP API 1.0 or HTTP API 2.0 event using JSON v2 directly. Register the Adapter object with lambda.Start(adapter), not its Invoke method as a reflected function. Transport/identity failures return no usable payload; ordinary HTTP error responses remain successful invocations. Panics propagate after cleanup. The caller must not mutate payload during use.\n\n```go\ntype InvocationError struct {\n\t// contains filtered or unexported fields\n}\n```\nInvocationError describes a sanitized transport failure. Use errors.Is to inspect its category and errors.AsType\\[\\*InvocationError] for its diagnostics. Its text is diagnostic, not a stable identifier or an HTTP response body. It does not expose event values, application data, or unsafe underlying errors. A zero InvocationError describes an unclassified failure.\n\nOperation failures precede any joined cleanup failures. Parent cancellation is returned as the standard context error when there is no operation or cleanup failure. Application panics propagated to the runtime are not InvocationErrors.\n\n```go\nfunc (e *InvocationError) Error() string\n```\nError returns a sanitized description of the failed operation.\n\n```go\nfunc (e *InvocationError) Limit() (resource Resource, maximum int64, ok bool)\n```\nLimit reports the exhausted resource, as one of the Resource constants, and its effective maximum in bytes for a limit failure. A response header or identity claims budget measures the documented charge; raw claims also have a wire-length limit. Neither budget measures heap use. Other failures return \"\", 0, false.\n\n```go\nfunc (e *InvocationError) Operation() Operation\n```\nOperation identifies the failed operation as one of the Operation constants. A zero error returns \"\".\n\n```go\nfunc (e *InvocationError) Unwrap() error\n```\nUnwrap exposes the failure category and any explicitly preserved safe causes.\n\n```go\ntype Operation string\n```\nOperation identifies the invocation stage that failed.\n\n```go\nconst (\n\tOperationValidate Operation = \"validate\" // adapter, argument or event envelope validation\n\tOperationDecode   Operation = \"decode\"   // event JSON decoding\n\tOperationRequest  Operation = \"request\"  // HTTP request conversion\n\tOperationIdentity Operation = \"identity\" // gateway identity construction or isolation\n\tOperationResponse Operation = \"response\" // HTTP response capture\n\tOperationEncode   Operation = \"encode\"   // response envelope or stream prefix encoding\n\tOperationCleanup  Operation = \"cleanup\"  // invocation-owned request cleanup\n\tOperationStream   Operation = \"stream\"   // stream lifecycle after handoff\n)\n```\nInvocation stages reported by [InvocationError.Operation](#InvocationError.Operation).\n\n```go\ntype Option func(*config)\n```\nOption configures an [Adapter](#Adapter) or [StreamingAdapter](#StreamingAdapter) during construction. Use the option functions provided by this package. A nil Option is invalid. Options apply in argument order; the last assignment to a scalar setting wins.\n\n```go\nfunc WithGatewayIdentity(enabled bool) Option\n```\nWithGatewayIdentity configures whether gateway assertions establish identity. The default is false. When enabled, the policy covers native IAM and JWT/Cognito assertions; it does not configure authorization in AWS or enable local token verification. Custom-authorizer contexts need an explicit mapper. Unsupported or conflicting assertions fail before running the HTTP handler.\n\n```go\nfunc WithIdentityClaimsBudget(bytes int) Option\n```\nWithIdentityClaimsBudget sets the gateway identity claims allowance in bytes. The default is 256 KiB; New and [NewStreaming](#NewStreaming) reject settings outside 1..6 MiB. Each claim value costs 64 bytes plus name, string and exact-number text bytes. Dedicated gateway scopes consume the same allowance. Raw claim JSON is also limited to this byte length. This is a resource policy, not a heap cap or AWS quota. It does not enable gateway identity.\n\n```go\nfunc WithResponseHeaderBudget(bytes int) Option\n```\nWithResponseHeaderBudget sets the response header resource budget in bytes. The default is 256 KiB. Both constructors reject settings outside 1..6 MiB; zero does not disable the bound. Each original value costs its name length, value length and 32 bytes; nil/empty slices cost their name length and 32. Generated headers also consume the budget. This is a library resource policy, not an AWS quota or a bound on total heap usage. It does not change the separate buffered envelope or streaming metadata limits.\n\n```go\nfunc WithStreamErrorReporter(report func(context.Context, error)) Option\n```\nWithStreamErrorReporter reports a sanitized terminal failure once after producer cleanup and before stream completion. It applies only to [NewStreaming](#NewStreaming); New rejects it. A final nil callback is invalid. The callback receives the invocation context, possibly canceled, and must return promptly. Pre-handoff failures are returned directly and not reported. A callback panic is recovered and adds a sanitized [ErrStream](#ErrStream) fault without replacing the original failure. It must not read or close the same stream: reporting precedes its completion.\n\n```go\ntype Resource string\n```\nResource names an adapter-enforced limit reported by [InvocationError.Limit](#InvocationError.Limit).\n\n```go\nconst (\n\tResourceResponseHeaders  Resource = \"response_headers\"  // weighted response header budget\n\tResourceBufferedBody     Resource = \"buffered_body\"     // buffered body, including base64 expansion and HEAD byte counts\n\tResourceBufferedEnvelope Resource = \"buffered_envelope\" // complete serialized buffered response\n\tResourceStreamMetadata   Resource = \"stream_metadata\"   // streaming metadata prefix\n\tResourceIdentityClaims   Resource = \"identity_claims\"   // weighted gateway identity claims allowance\n)\n```\nResources whose limits the adapter enforces.\n\n```go\ntype StreamingAdapter struct {\n\t// contains filtered or unexported fields\n}\n```\nStreamingAdapter serves REST API proxy events through an ordinary HTTP handler and returns a metadata-prefixed body stream. Construct it with [NewStreaming](#NewStreaming); its zero value is unusable. Configuration is immutable; the application owns handler concurrency safety. HTTP APIs and request streaming are unsupported.\n\nDeployment requires a REST STREAM integration using InvokeWithResponseStream. SDK Runtime API compatibility remains unverified against live AWS; see the module's streaming guide for the documented SDK/header/connection qualification.\n\n```go\nfunc NewStreaming(handler http.Handler, opts ...Option) (*StreamingAdapter, error)\n```\nNewStreaming validates handler and options without starting I/O or goroutines. It shares New's handler, header-budget, identity-budget and gateway defaults. Streaming never infers Content-Length; supply it explicitly when needed. Authenticate and authorize before writing or flushing any response.\n\n```go\nfunc (a *StreamingAdapter) Handle(ctx context.Context, event jsontext.Value) (io.ReadCloser, error)\n```\nHandle validates raw REST event JSON with JSON v2 and returns a stream that callers must consume and Close. Register lambda.Start(adapter.Handle), not the adapter object or the buffered Handler.Invoke boundary. The SDK owns its initial jsontext.Value capture; edge owns strict event decoding and prefix encoding. Explicit HTTP API version envelopes are rejected. Do not mutate event during the call. Request resources remain owned until producer cleanup completes.\n\nPre-handoff failures return a nil stream. Early producer panics propagate after cleanup; late panics become sanitized terminal errors. After handoff, failures cannot replace status or bytes. Close cancels and joins the producer; a handler ignoring cancellation/write errors can delay Close until invocation timeout.\n\n```go\nfunc (a *StreamingAdapter) HandleV1(ctx context.Context, event events.APIGatewayProxyRequest) (io.ReadCloser, error)\n```\nHandleV1 accepts an already typed REST event, avoiding request envelope JSON work inside edge. Register lambda.Start(adapter.HandleV1). The caller/upstream codec owns wire validation and numeric fidelity. The V1 type also represents HTTP API 1.0; it cannot prove the deployment is a REST streaming integration. Its stream ownership and error contract match Handle. Inputs must not change during the call. Streaming metadata still requires direct JSON v2 encoding.\n\n","path":"github.com/asteroid-computing/go-lambda-edge","name":"edge","synopsis":"Package edge adapts AWS API Gateway Lambda proxy events to net/http handlers.","isRedistributable":true}
