uselambda

package module
v0.0.0-...-5a7fe2c Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: MIT Imports: 11 Imported by: 0

README

uselambda

AWS Lambad middleware, like gin.

Example

package main

import (
	"fmt"
	"net/http"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/immysec/uselambda"
)

func SayHello(ctx *uselambda.Context) (interface{}, error) {
	res := &events.APIGatewayProxyResponse{
		StatusCode: http.StatusOK,
		Body:       "Hello!",
	}
	return ctx.Return(res)
}

func Middleware(ctx *uselambda.Context) (interface{}, error) {
	fmt.Println("enter middleware first")
	return ctx.Next()
}

func main() {
	lambda.StartHandler(uselambda.Use(Middleware).Handle(SayHello))
}

Documentation

Index

Constants

View Source
const (
	MIMEApplicationJSON            = "application/json"
	MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8
	MIMETextPlain                  = "text/plain"
	MIMETextPlainCharsetUTF8       = MIMETextPlain + "; " + charsetUTF8
)
View Source
const (
	HeaderContentType = "Content-Type"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Payload Payload

	Keys map[string]interface{}
	// contains filtered or unexported fields
}

func (*Context) Abort

func (ctx *Context) Abort()

func (*Context) Base64

func (ctx *Context) Base64(statusCode int, body []byte) (interface{}, error)

func (*Context) Deadline

func (ctx *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

func (*Context) Err

func (ctx *Context) Err() error

func (*Context) Get

func (ctx *Context) Get(key string) (interface{}, bool)

func (*Context) IsAborted

func (ctx *Context) IsAborted() bool

func (*Context) JSON

func (ctx *Context) JSON(statusCode int, body interface{}) (interface{}, error)

func (*Context) MustGet

func (ctx *Context) MustGet(key string) interface{}

func (*Context) Next

func (ctx *Context) Next() (res interface{}, err error)

func (*Context) Return

func (ctx *Context) Return(res interface{}) (interface{}, error)

func (*Context) Set

func (ctx *Context) Set(key string, value interface{})

func (*Context) String

func (ctx *Context) String(statusCode int, body string) (interface{}, error)

func (*Context) Value

func (ctx *Context) Value(key interface{}) interface{}

type ErrHandler

type ErrHandler func(error, *Context) (interface{}, error)
var DefaultErrHandler ErrHandler = func(err error, ctx *Context) (interface{}, error) {
	return &events.APIGatewayProxyResponse{
		StatusCode: http.StatusInternalServerError,
		Body:       http.StatusText(http.StatusInternalServerError) + ": " + err.Error(),
	}, nil
}

type H

type H map[string]interface{}

type Handler

type Handler func(ctx *Context) (interface{}, error)

type Lambda

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

func Use

func Use(handlers ...Handler) *Lambda

func (*Lambda) Handle

func (l *Lambda) Handle(handler Handler) *Lambda

func (*Lambda) Invoke

func (l *Lambda) Invoke(parent context.Context, payload []byte) (out []byte, err error)

func (*Lambda) SetErrHandler

func (l *Lambda) SetErrHandler(handler ErrHandler) *Lambda

func (*Lambda) Use

func (l *Lambda) Use(handlers ...Handler) *Lambda

func (*Lambda) With

func (l *Lambda) With(key string, value interface{}) *Lambda

type Payload

type Payload []byte

func (Payload) AsRequest

func (p Payload) AsRequest() *events.APIGatewayProxyRequest

func (Payload) AsWsRequest

func (Payload) MustUnmarshal

func (p Payload) MustUnmarshal(dst interface{}) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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