httplam

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 14 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

httplam

httplam is a library that bind AWS Lambda, AWS API Gateway to net/http

Install

go get -u github.com/aws-serverless-go/httplam

Examples

net/http

package main

import (
	"github.com/aws-serverless-go/httplam"
	"net/http"
)

func main() {
	m := http.NewServeMux()
	m.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		writer.Write([]byte("welcome"))
	})
	if httplam.IsLambdaRuntime() {
		httplam.StartLambdaWithAPIGateway(m)
	} else {
		http.ListenAndServe(":3000", m)
	}
}

github.com/julienschmidt/httprouter

package main

import (
	"fmt"
	"github.com/aws-serverless-go/httplam"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}

func main() {
	router := httprouter.New()
	router.GET("/", Index)
	router.GET("/hello/:name", Hello)

	if httplam.IsLambdaRuntime() {
		httplam.StartLambdaWithAPIGateway(router)
	} else {
		log.Fatal(http.ListenAndServe(":8080", router))
	}
}

github.com/go-chi/chi

package main

import (
	"github.com/aws-serverless-go/httplam"
	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"net/http"
)

func main() {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("welcome"))
	})
	if httplam.IsLambdaRuntime() {
		httplam.StartLambdaWithAPIGateway(r)
	} else {
		http.ListenAndServe(":3000", r)
	}
}

License

MIT License

Documentation

Index

Constants

View Source
const (
	MIMEApplicationJSON            = "application/json"
	MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEApplicationXML             = "application/xml"
	MIMEApplicationXMLCharsetUTF8  = MIMEApplicationXML + "; " + charsetUTF8
	MIMETextHTML                   = "text/html"
	MIMETextHTMLCharsetUTF8        = MIMETextHTML + "; " + charsetUTF8
	MIMETextPlain                  = "text/plain"
	MIMETextPlainCharsetUTF8       = MIMETextPlain + "; " + charsetUTF8
)
View Source
const (
	HeaderContentType        = "Content-Type"
	HeaderSetCookie          = "Set-Cookie"
	HeaderXForwardedProto    = "X-Forwarded-Proto"
	HeaderXForwardedProtocol = "X-Forwarded-Protocol"
	HeaderXForwardedSsl      = "X-Forwarded-Ssl"
	HeaderXUrlScheme         = "X-Url-Scheme"
	HeaderHost               = "Host"
)

Variables

This section is empty.

Functions

func GetLambdaRequest

func GetLambdaRequest(ctx context.Context) (req *events.APIGatewayV2HTTPRequest)

func IsLambdaRuntime

func IsLambdaRuntime() bool

func NewHTTPRequest

func NewHTTPRequest(ctx context.Context, from *events.APIGatewayV2HTTPRequest) (req *http.Request, err error)

func StartLambdaWithAPIGateway

func StartLambdaWithAPIGateway(handler http.Handler)

Types

type APIGatewayV2HTTPResponseBuilder

type APIGatewayV2HTTPResponseBuilder struct {
	// contains filtered or unexported fields
}

func NewAPIGatewayV2HTTPResponseBuilder

func NewAPIGatewayV2HTTPResponseBuilder(target *events.APIGatewayV2HTTPResponse) (res *APIGatewayV2HTTPResponseBuilder)

func (*APIGatewayV2HTTPResponseBuilder) Build

func (*APIGatewayV2HTTPResponseBuilder) Header

func (*APIGatewayV2HTTPResponseBuilder) Hijack

func (*APIGatewayV2HTTPResponseBuilder) IsDone

func (*APIGatewayV2HTTPResponseBuilder) SetCookie

func (w *APIGatewayV2HTTPResponseBuilder) SetCookie(cookie *http.Cookie)

func (*APIGatewayV2HTTPResponseBuilder) Write

func (w *APIGatewayV2HTTPResponseBuilder) Write(bytes []byte) (int, error)

func (*APIGatewayV2HTTPResponseBuilder) WriteHeader

func (w *APIGatewayV2HTTPResponseBuilder) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL