lambda-go-extras

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: Apache-2.0

README

lambda-go-extras

This module provides a middleware layer for github.com/aws/aws-lambda-go. This project is heavily based on https://github.com/justinas/alice.

GitHub Actions status Go Report Card Documentation Coverage Status

Usage

This illustrates how easy it is to dump the input and output payloads using a simple middleware chain.

package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-lambda-go/lambda"
	"github.com/wolfeidau/lambda-go-extras/lambdaextras"
	lmw "github.com/wolfeidau/lambda-go-extras/middleware"
)

func main() {

	ch := lmw.New(logEvent).ThenFunc(processEvent)

	lambda.StartHandler(ch)
}

func logEvent(next lambda.Handler) lambda.Handler {
	return lambdaextras.HandlerFunc(func(ctx context.Context, payload []byte) ([]byte, error) {

		fmt.Println(string(payload))

		result, err := next.Invoke(ctx, payload)

		fmt.Println(string(result))

		return result, err
	})
}

func processEvent(ctx context.Context, payload []byte) ([]byte, error) {
	return []byte("ok"), nil
}

License

This code was authored by Mark Wolfe and is licensed under the Apache 2.0 license.

Directories

Path Synopsis
example module
Package lambdaextras contains extras for building Go based lambdas.
Package lambdaextras contains extras for building Go based lambdas.
Package middleware implements a middleware chaining solution for Go based lambdas.
Package middleware implements a middleware chaining solution for Go based lambdas.
raw module
zerolog module
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
standard module

Jump to

Keyboard shortcuts

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