Categorygithub.com/getas/alb-gateway
modulepackage
1.0.1
Repository: https://github.com/getas/alb-gateway.git
Documentation: pkg.go.dev

# README

Package alb-gateway is based on a fork of Apex/gateway

This package provides a drop-in replacement for net/http's ListenAndServe for use in an AWS Lambda invoked by a ALB Labmda Target Group, simply swap it out for gateway.ListenAndServe.

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/getas/alb-gateway"
	"github.com/aws/aws-lambda-go"
)

func main() {
	http.HandleFunc("/", hello)
	log.Fatal(gateway.ListenAndServe(":3000", nil))
}

func hello(w http.ResponseWriter, r *http.Request) {
	// example retrieving values from the api gateway proxy request context.
	_, ok := gateway.RequestContext(r.Context())
	if !ok {
		fmt.Fprint(w, "Hello World from Go")
		return
	}

	fmt.Fprintf(w, "Hello %s from Go", r.RemoteAddr)
}

# Functions

ListenAndServe is a drop-in replacement for http.ListenAndServe for use within AWS Lambda.
NewRequest returns a new http.Request from the given Lambda event.
NewResponse returns a new response writer to capture http output.
RequestContext returns the ALBLambdaRequestContext value stored in ctx.

# Structs

ResponseWriter implements the http.ResponseWriter interface in order to support the API Gateway Lambda HTTP "protocol".