Categorygithub.com/unquietcode/gateway
modulepackage
0.0.1
Repository: https://github.com/unquietcode/gateway.git
Documentation: pkg.go.dev

# README

Package gateway provides a drop-in replacement for net/http's ListenAndServe for use in AWS Lambda & API Gateway, simply swap it out for gateway.ListenAndServe. Extracted from Up which provides additional middleware features and operational functionality.

package main

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

	"github.com/apex/gateway"
)

func main() {
	addr := ":" + os.Getenv("PORT")
	http.HandleFunc("/", hello)
	log.Fatal(gateway.ListenAndServe(addr, nil))
}

func hello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "Hello World from Go")
}

GoDoc

# 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.

# Structs

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