lhttp

package module
v0.0.0-...-de3ef78 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

lhttp: a Go Lambda Proxy

With lhttp you can deploy idiomatic Go HTTP server code as an AWS Lambda function using AWS Api Gateway.

For example, this is a basic Go server from the http package Godoc:

http.Handle("/foo", fooHandler)

http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})

log.Fatal(http.ListenAndServe(":8080", nil))

This is the equivalent implementation using lhttp:

lhttp.Handle("/foo", fooHandler)

lhttp.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})

log.Fatal(lhttp.ListenAndServe("", nil))

See the examples for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultServeMux = &defaultServeMux

DefaultServeMux is the default ServeMux used by Serve.

View Source
var LambdaContextKey = contextKey{"lambda-context"}

LambdaContextKey is a context key. It can be used by handlers to access the AWS Lambda Context from the Request object. The associated value will be of type LambdaContext

View Source
var LambdaRequestContextKey = contextKey{"lambda-request-context"}

LambdaRequestContextKey is a context key. It can be used by handlers to access the AWS Lambda Request Context from the Request object.

Functions

func Handle

func Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern in the DefaultServeMux. The documentation for http.ServeMux explains how patterns are matched.

func HandleFunc

func HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern in the DefaultServeMux. The documentation for http.ServeMux explains how patterns are matched.

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

ListenAndServe listens for incoming requests and dispatches them to the configured handler

Types

type Authorizer

type Authorizer struct {
	PrincipalID string `json:"principalId"`
	Claims      map[string]string
}

type LambdaContext

type LambdaContext struct {
	AwsRequestID             string `json:"awsRequestId"`
	FunctionName             string `json:"functionName"`
	FunctionVersion          string `json:"functionVersion"`
	InvokeID                 string `json:"invokeid"`
	IsDefaultFunctionVersion bool   `json:"isDefaultFunctionVersion"`
	LogGroupName             string `json:"logGroupName"`
	LogStreamName            string `json:"logStreamName"`
	MemoryLimitInMB          string `json:"memoryLimitInMB"`
}

LambdaContext is the AWS Lambda request context

type LambdaRequestContext

type LambdaRequestContext struct {
	AccountID    string            `json:"accountId"`
	ResourceID   string            `json:"resourceId"`
	Stage        string            `json:"stage"`
	RequestID    string            `json:"requestId"`
	Identity     map[string]string `json:"identity"`
	Authorizer   Authorizer        `json:"authorizer"`
	ResourcePath string            `json:"resourcePath"`
	HTTPMethod   string            `json:"httpMethod"`
	APIID        string            `json:"apiId"`
}

type LambdaServer

type LambdaServer struct {
	Handler http.Handler // handler to invoke, http.DefaultServeMux if nil
}

LambdaServer is an analog of http.Server to handle Lambda requests

func (*LambdaServer) ListenAndServe

func (srv *LambdaServer) ListenAndServe() error

ListenAndServe listens for incoming requests and dispatches them to the configured handler

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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