{"id":20853710,"url":"https://github.com/wolfeidau/lambda-go-extras","last_synced_at":"2025-05-12T05:31:32.512Z","repository":{"id":51151548,"uuid":"256965942","full_name":"wolfeidau/lambda-go-extras","owner":"wolfeidau","description":"This module provides a middleware layer for github.com/aws/aws-lambda-go. ","archived":false,"fork":false,"pushed_at":"2024-01-03T22:59:01.000Z","size":76,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T01:21:26.756Z","etag":null,"topics":["aws","aws-lambda","golang","middleware"],"latest_commit_sha":null,"homepage":"https://github.com/wolfeidau/lambda-go-extras","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wolfeidau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-19T09:58:00.000Z","updated_at":"2025-03-10T16:13:47.000Z","dependencies_parsed_at":"2024-01-04T01:13:33.778Z","dependency_job_id":"352e1250-e55b-4b28-86c2-802a2191db71","html_url":"https://github.com/wolfeidau/lambda-go-extras","commit_stats":{"total_commits":21,"total_committers":2,"mean_commits":10.5,"dds":0.4285714285714286,"last_synced_commit":"a16ed26a83b6a838b0687a06b1f33c17704afae1"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Flambda-go-extras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Flambda-go-extras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Flambda-go-extras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Flambda-go-extras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wolfeidau","download_url":"https://codeload.github.com/wolfeidau/lambda-go-extras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253682147,"owners_count":21946888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-lambda","golang","middleware"],"created_at":"2024-11-18T03:22:53.029Z","updated_at":"2025-05-12T05:31:27.499Z","avatar_url":"https://github.com/wolfeidau.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lambda-go-extras\n\nThis module provides a middleware layer for [github.com/aws/aws-lambda-go](https://github.com/aws/aws-lambda-go). This project is heavily based on https://github.com/justinas/alice.\n\n[![GitHub Actions status](https://github.com/wolfeidau/lambda-go-extras/workflows/Go/badge.svg?branch=master)](https://github.com/wolfeidau/lambda-go-extras/actions?query=workflow%3AGo)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wolfeidau/lambda-go-extras)](https://goreportcard.com/report/github.com/wolfeidau/lambda-go-extras)\n[![Documentation](https://godoc.org/github.com/wolfeidau/lambda-go-extras?status.svg)](https://godoc.org/github.com/wolfeidau/lambda-go-extras)\n\n# Why?\n\nHaving used the `github.com/aws/aws-lambda-go` package for a while now I have found it annoying switching between the Go standard libraries `http` package and this library. After some review I think the thing I miss the most is the ability to chain a list of handlers, with each link responsible for a part of the puzzle.\n\nBeing able to compose these chains offers a lot of flexibility and reuse across projects.\n\nGiven the default way of using the `github.com/aws/aws-lambda-go` is via the [Start(handler interface{})](https://godoc.org/github.com/aws/aws-lambda-go/lambda#Start) function, which is very flexible, but not easily extended due it's dynamic nature. So I have moved to using the less used [func StartHandler(handler Handler)](https://godoc.org/github.com/aws/aws-lambda-go/lambda#StartHandler) which is more idiomatic with its `Handler` being just an interface with a single `Invoke` method. This module has extended this with a simple middleware chain inspired by alice as mentioned above.\n\n# Usage\n\nThis illustrates how easy it is to dump the input and output payloads using a simple middleware chain.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\n\t\"github.com/aws/aws-lambda-go/events\"\n\t\"github.com/aws/aws-lambda-go/lambda\"\n\t\"github.com/rs/zerolog\"\n\t\"github.com/wolfeidau/lambda-go-extras/lambdaextras\"\n\tlmw \"github.com/wolfeidau/lambda-go-extras/middleware\"\n\t\"github.com/wolfeidau/lambda-go-extras/middleware/raw\"\n\tzlog \"github.com/wolfeidau/lambda-go-extras/middleware/zerolog\"\n)\n\nvar (\n\tcommit    = \"unknown\"\n\tbuildDate = \"unknown\"\n)\n\nfunc main() {\n\tflds := lmw.FieldMap{\"commit\": commit, \"buildDate\": buildDate}\n\n\tch := lmw.New(\n\t\traw.New(raw.Fields(flds)),   // raw event logger which prints input and output of handler\n\t\tzlog.New(zlog.Fields(flds)), // inject zerolog into the context\n\t).Then(lambdaextras.GenericHandler(processSQSEvent))\n\n\t// use StartWithOptions as StartHandler is deprecated\n\tlambda.StartWithOptions(ch)\n}\n\nfunc processSQSEvent(ctx context.Context, sqsEvent events.SQSEvent) (string, error) {\n\tzerolog.Ctx(ctx).Info().Msg(\"sqsEvent\")\n\treturn \"ok\", nil\n}\n```\n\nThere are two bundled middleware, these are \n\n* `github.com/wolfeidau/lambda-go-extras/middleware/raw` - raw event logger which outputs input and output events which also includes `aws_request_id` and the fields you provide at initialisation.\n* `github.com/wolfeidau/lambda-go-extras/middleware/zerolog` - configures the context with a [zerolog](https://github.com/rs/zerolog) logger which includes `aws_request_id` and the fields you provide at initialisation.\n\n# License\n\nThis code was authored by [Mark Wolfe](https://www.wolfe.id.au) and is licensed under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfeidau%2Flambda-go-extras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwolfeidau%2Flambda-go-extras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfeidau%2Flambda-go-extras/lists"}