### ListenAndServe Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Starts the AWS Lambda runtime with a given HTTP handler. ```APIDOC ## ListenAndServe ### Description ListenAndServe starts the AWS Lambda runtime (aws-lambda-go lambda.Start) with a given handler. ### Signature ```go func ListenAndServe(handler http.Handler, opts *Options) ``` ``` -------------------------------- ### Start AWS Lambda Runtime with HTTP Handler Source: https://pkg.go.dev/github.com/akrylysov/algnhsa ListenAndServe starts the AWS Lambda runtime using aws-lambda-go lambda.Start with a provided HTTP handler. This is the main function to integrate your HTTP server with Lambda. ```go func ListenAndServe(handler http.Handler, opts *Options) ``` -------------------------------- ### Basic algnhsa Server with Standard Handlers Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This example demonstrates setting up a basic Go HTTP server using algnhsa. It includes handlers for addition and accessing Lambda context. Use this for standard Go http.Handler implementations. ```go package main import ( "fmt" "net/http" "strconv" "github.com/akrylysov/algnhsa" ) func addHandler(w http.ResponseWriter, r *http.Request) { f, _ := strconv.Atoi(r.FormValue("first")) s, _ := strconv.Atoi(r.FormValue("second")) w.Header().Set("X-Hi", "foo") fmt.Fprintf(w, "%d", f+s) } func contextHandler(w http.ResponseWriter, r *http.Request) { lambdaEvent, ok := algnhsa.APIGatewayV2RequestFromContext(r.Context()) if ok { fmt.Fprint(w, lambdaEvent.RequestContext.AccountID) } } func main() { http.HandleFunc("/add", addHandler) http.HandleFunc("/context", contextHandler) algn hsa.ListenAndServe(http.DefaultServeMux, nil) } ``` -------------------------------- ### Integrate Gin Web Framework with algnhsa Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This example shows how to use algnhsa with the Gin web framework. It's suitable when you are already using Gin and want to deploy it on AWS Lambda. ```go package main import ( "net/http" "github.com/akrylysov/algnhsa" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "hi", }) }) algn hsa.ListenAndServe(r, nil) } ``` -------------------------------- ### Integrate Echo Web Framework with algnhsa Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This example demonstrates integrating the Echo web framework with algnhsa. Use this if your project utilizes Echo for routing and request handling. ```go package main import ( "net/http" "github.com/akrylysov/algnhsa" "github.com/labstack/echo/v4" ) func main() { e := echo.New() e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "hi") }) algn hsa.ListenAndServe(e, nil) } ``` -------------------------------- ### Integrate Fiber Web Framework with algnhsa Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This example demonstrates using algnhsa with the Fiber web framework. It utilizes the adaptor to bridge Fiber's application with the Lambda handler. ```go package main import ( "github.com/akrylysov/algnhsa" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/adaptor" ) func main() { app := fiber.New() app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, World!") }) algn hsa.ListenAndServe(adaptor.FiberApp(app), nil) } ``` -------------------------------- ### Integrate Chi Router with algnhsa Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This example shows how to use algnhsa with the Chi router. It's useful for projects that prefer Chi for building their HTTP services. ```go package main import ( "net/http" "github.com/akrylysov/algnhsa" "github.com/go-chi/chi" ) func main() { r := chi.NewRouter() r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hi")) }) algn hsa.ListenAndServe(r, nil) } ``` -------------------------------- ### Basic Usage with Standard Go HTTP Handlers Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Demonstrates how to use algnhsa to run standard Go HTTP handlers on AWS Lambda. It includes examples for handling requests and accessing Lambda event context. ```APIDOC ## Basic Usage with Standard Go HTTP Handlers This example shows how to integrate standard Go `net/http` handlers with `algnhsa`. ### Description This code snippet demonstrates how to set up a basic Go HTTP server that can be run on AWS Lambda using `algnhsa`. It includes two example handlers: `addHandler` for processing form values and `contextHandler` for accessing Lambda event details from the request context. ### Code Example ```go package main import ( "fmt" "net/http" "strconv" "github.com/akrylysov/algnhsa" ) func addHandler(w http.ResponseWriter, r *http.Request) { f, _ := strconv.Atoi(r.FormValue("first")) s, _ := strconv.Atoi(r.FormValue("second")) w.Header().Set("X-Hi", "foo") fmt.Fprintf(w, "%d", f+s) } func contextHandler(w http.ResponseWriter, r *http.Request) { lambdaEvent, ok := algnhsa.APIGatewayV2RequestFromContext(r.Context()) if ok { fmt.Fprint(w, lambdaEvent.RequestContext.AccountID) } } func main() { http.HandleFunc("/add", addHandler) http.HandleFunc("/context", contextHandler) algnhsa.ListenAndServe(http.DefaultServeMux, nil) } ``` ``` -------------------------------- ### Create New Lambda Handler for HTTP Source: https://pkg.go.dev/github.com/akrylysov/algnhsa New returns a new lambda.Handler for a given http.Handler. The caller is responsible for starting the Lambda runtime with the returned handler using lambda.Start(). ```go func New(handler http.Handler, opts *Options) lambda.Handler ``` -------------------------------- ### Build Go Application for AWS Lambda Deployment Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This command builds a Go application for Linux, targeting AWS Lambda deployment. Ensure you use the correct environment variables for the build. ```bash GOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o bootstrap zip function.zip bootstrap ``` -------------------------------- ### Integrating with Gin Web Framework Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Shows how to use algnhsa to adapt a Gin web framework application for AWS Lambda. ```APIDOC ## Integrating with Gin Web Framework This example demonstrates how to use `algnhsa` to run a Gin web application on AWS Lambda. ### Description This code snippet shows the setup for a simple Gin application. The `algnhsa.ListenAndServe` function is used to adapt the Gin router (`r`) for AWS Lambda. ### Code Example ```go package main import ( "net/http" "github.com/akrylysov/algnhsa" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "hi", }) }) algnhsa.ListenAndServe(r, nil) } ``` ``` -------------------------------- ### Integrating with Echo Web Framework Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Shows how to use algnhsa to adapt an Echo web framework application for AWS Lambda. ```APIDOC ## Integrating with Echo Web Framework This example demonstrates how to use `algnhsa` to run an Echo web application on AWS Lambda. ### Description This code snippet shows the setup for a simple Echo application. The `algnhsa.ListenAndServe` function is used to adapt the Echo router (`e`) for AWS Lambda. ### Code Example ```go package main import ( "net/http" "github.com/akrylysov/algnhsa" "github.com/labstack/echo/v4" ) func main() { e := echo.New() e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "hi") }) algnhsa.ListenAndServe(e, nil) } ``` ``` -------------------------------- ### Integrating with Fiber Web Framework Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Shows how to use algnhsa to adapt a Fiber web framework application for AWS Lambda. ```APIDOC ## Integrating with Fiber Web Framework This example demonstrates how to use `algnhsa` to run a Fiber web application on AWS Lambda. ### Description This code snippet shows the setup for a simple Fiber application. The `adaptor.FiberApp` function is used to adapt the Fiber app, and then `algnhsa.ListenAndServe` is used to adapt it for AWS Lambda. ### Code Example ```go package main import ( "github.com/akrylysov/algnhsa" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/adaptor" ) func main() { app := fiber.New() app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, World!") }) algnhsa.ListenAndServe(adaptor.FiberApp(app), nil) } ``` ``` -------------------------------- ### Integrating with Chi Web Framework Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Shows how to use algnhsa to adapt a Chi web framework application for AWS Lambda. ```APIDOC ## Integrating with Chi Web Framework This example demonstrates how to use `algnhsa` to run a Chi web application on AWS Lambda. ### Description This code snippet shows the setup for a simple Chi router. The `algnhsa.ListenAndServe` function is used to adapt the Chi router (`r`) for AWS Lambda. ### Code Example ```go package main import ( "net/http" "github.com/akrylysov/algnhsa" "github.com/go-chi/chi" ) func main() { r := chi.NewRouter() r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hi")) }) algnhsa.ListenAndServe(r, nil) } ``` ``` -------------------------------- ### New Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Creates a new Lambda handler for a given HTTP handler. ```APIDOC ## New ### Description New returns a new lambda handler for the given http.Handler. It is up to the caller of New to run lamdba.Start(handler) with the returned handler. ### Signature ```go func New(handler http.Handler, opts *Options) lambda.Handler ``` ``` -------------------------------- ### Create Request Debug Dump Source: https://pkg.go.dev/github.com/akrylysov/algnhsa NewRequestDebugDump creates a new RequestDebugDump object from an http.Request. This object contains detailed information about the request, including the original Lambda event. ```go func NewRequestDebugDump(r *http.Request) (*RequestDebugDump, error) ``` -------------------------------- ### Extract APIGatewayV1Request from Context Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Use APIGatewayV1RequestFromContext to extract the APIGatewayProxyRequest event from the context. This is useful when you need to access specific details of the API Gateway v1 event. ```go func APIGatewayV1RequestFromContext(ctx context.Context) (events.APIGatewayProxyRequest, bool) ``` -------------------------------- ### APIGatewayV1RequestFromContext Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Extracts the APIGatewayProxyRequest event from the provided context. ```APIDOC ## APIGatewayV1RequestFromContext ### Description Extracts the APIGatewayProxyRequest event from ctx. ### Signature ```go func APIGatewayV1RequestFromContext(ctx context.Context) (events.APIGatewayProxyRequest, bool) ``` ``` -------------------------------- ### APIGatewayV2RequestFromContext Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Extracts the APIGatewayV2HTTPRequest event from the provided context. ```APIDOC ## APIGatewayV2RequestFromContext ### Description Extracts the APIGatewayV2HTTPRequest event from ctx. ### Signature ```go func APIGatewayV2RequestFromContext(ctx context.Context) (events.APIGatewayV2HTTPRequest, bool) ``` ``` -------------------------------- ### ALBRequestFromContext Function Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Extracts the ALBTargetGroupRequest event from the request context. ```APIDOC ## ALBRequestFromContext ### Description `ALBRequestFromContext` extracts the `events.ALBTargetGroupRequest` event from the provided `context.Context`. ### Function Signature ```go func ALBRequestFromContext(ctx context.Context) (events.ALBTargetGroupRequest, bool) ``` ### Parameters * **ctx** (context.Context) - The context from which to extract the ALB target group request. ### Returns * **events.ALBTargetGroupRequest** - The extracted ALB target group request event. * **bool** - A boolean indicating whether the extraction was successful. ``` -------------------------------- ### NewRequestDebugDump Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Creates a new RequestDebugDump from an HTTP request. ```APIDOC ## NewRequestDebugDump ### Description NewRequestDebugDump creates a new RequestDebugDump from an HTTP request. ### Signature ```go func NewRequestDebugDump(r *http.Request) (*RequestDebugDump, error) ``` ``` -------------------------------- ### Extract ALB Target Group Request from Context Source: https://pkg.go.dev/github.com/akrylysov/algnhsa This function extracts the ALBTargetGroupRequest event from the provided context. It returns the request and a boolean indicating success. ```go func ALBRequestFromContext(ctx context.Context) (events.ALBTargetGroupRequest, bool) ``` -------------------------------- ### Extract APIGatewayV2Request from Context Source: https://pkg.go.dev/github.com/akrylysov/algnhsa Use APIGatewayV2RequestFromContext to extract the APIGatewayV2HTTPRequest event from the context. This is useful for accessing details specific to API Gateway v2 events. ```go func APIGatewayV2RequestFromContext(ctx context.Context) (events.APIGatewayV2HTTPRequest, bool) ``` -------------------------------- ### RequestDebugDumpHandler Source: https://pkg.go.dev/github.com/akrylysov/algnhsa An HTTP handler that returns a JSON encoded RequestDebugDump. ```APIDOC ## RequestDebugDumpHandler ### Description RequestDebugDumpHandler is an HTTP handler that returns JSON encoded RequestDebugDump. ### Signature ```go func RequestDebugDumpHandler(w http.ResponseWriter, r *http.Request) ``` ``` -------------------------------- ### HTTP Handler for Request Debug Dumping Source: https://pkg.go.dev/github.com/akrylysov/algnhsa RequestDebugDumpHandler is an HTTP handler that generates and returns a JSON-encoded dump of the incoming HTTP request. It's useful for debugging. ```go func RequestDebugDumpHandler(w http.ResponseWriter, r *http.Request) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.