delta

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 15 Imported by: 0

README

δelta

Use golang http handler in AWS Lambda

usage

func helloHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("x-powered-by", "delta")
	fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
}

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/hello/", helloHandler)

	// start lambda handling if it runs on lambda
	// otherwise start http server on port 3000
	delta.ServeOrStartLambda(":3000", mux)
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLambdaEvent

func GetLambdaEvent(ctx context.Context) (*events.APIGatewayProxyRequest, error)

GetLambdaEvent from context

func GetLambdaEventV2

func GetLambdaEventV2(ctx context.Context) (*events.APIGatewayV2HTTPRequest, error)

GetLambdaEventV2 from context

func NewHandler

func NewHandler(h http.Handler, opts ...Options) lambda.Handler

func ServeOrStartLambda

func ServeOrStartLambda(addr string, h http.Handler, opts ...Options) error

ServeOrStartLambda will start http server if it's not in lambda environment, otherwise it starts handling lambda

func SetBase64Encoding

func SetBase64Encoding(w http.ResponseWriter, enabled bool) error

SetBase64Encoding overrides base64 encoding for this response see Configuration.SetBase64Encoding

func Start

func Start(h http.Handler, opts ...Options)

Start lambda server

Example: mux := http.NewServeMux() mux.Handle("/", handeHandler) delta.Start(nil, mux)

Types

type Handler

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

func (*Handler) Invoke

func (lh *Handler) Invoke(ctx context.Context, payload []byte) ([]byte, error)

Invoke implements lambda.Handler

func (*Handler) ServeHTTP

func (lh *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Options

type Options func(*config)

func WithALB

func WithALB() Options

func WithAPIGatewayV1

func WithAPIGatewayV1() Options

func WithAPIGatewayV2

func WithAPIGatewayV2() Options

func WithEncodeResponse

func WithEncodeResponse() Options

func WithLambdaURL

func WithLambdaURL() Options

func WithTransformer

func WithTransformer(t Transformer) Options

type ResponseWriter

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

ResponseWriter implements http.ResponseWriter used for buffering response

func NewResponseWriter

func NewResponseWriter() *ResponseWriter

NewResponseWriter creates new empty ResponseWriter

func (*ResponseWriter) Header

func (r *ResponseWriter) Header() http.Header

Header returns http.Header. You can modify it to send response header

func (*ResponseWriter) Write

func (r *ResponseWriter) Write(chunk []byte) (int, error)

Write appends chunk to response body

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(statusCode int)

WriteHeader set status code of current request

type Transformer

type Transformer interface {
	ToReq(context.Context, []byte) (*http.Request, error)
	FromRes(context.Context, *ResponseWriter) ([]byte, error)
}

Jump to

Keyboard shortcuts

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