{"id":37213064,"url":"https://github.com/jpcedenog/gointercept","last_synced_at":"2026-01-15T00:33:13.671Z","repository":{"id":41544510,"uuid":"271888156","full_name":"jpcedenog/gointercept","owner":"jpcedenog","description":"A Go middleware library for AWS Lambdas.","archived":false,"fork":false,"pushed_at":"2021-01-19T04:25:22.000Z","size":641,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-26T10:08:07.458Z","etag":null,"topics":["aws","aws-lambda","framework","go","golang","lambda-handler","middleware","serverless"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpcedenog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-12T20:52:02.000Z","updated_at":"2022-07-03T21:50:31.000Z","dependencies_parsed_at":"2022-08-26T05:10:47.074Z","dependency_job_id":null,"html_url":"https://github.com/jpcedenog/gointercept","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/jpcedenog/gointercept","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpcedenog%2Fgointercept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpcedenog%2Fgointercept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpcedenog%2Fgointercept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpcedenog%2Fgointercept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpcedenog","download_url":"https://codeload.github.com/jpcedenog/gointercept/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpcedenog%2Fgointercept/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439739,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","framework","go","golang","lambda-handler","middleware","serverless"],"created_at":"2026-01-15T00:33:13.063Z","updated_at":"2026-01-15T00:33:13.657Z","avatar_url":"https://github.com/jpcedenog.png","language":"Go","funding_links":["https://www.buymeacoffee.com/jpcedenog"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"Go Intercept\" src=\"img/GoIntercept.jpg\"/\u003e\n  \u003cp\u003e\u003cstrong\u003eElegant and modular middleware for AWS Lambdas with Golang\u003c/strong\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/jpcedenog/gointercept)](https://pkg.go.dev/github.com/jpcedenog/gointercept)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/jpcedenog/gointercept.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/jpcedenog/gointercept/alerts/)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjpcedenog%2Fgointercept.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjpcedenog%2Fgointercept?ref=badge_shield)\n[![Go Report Card](https://goreportcard.com/badge/github.com/jpcedenog/gointercept)](https://goreportcard.com/report/github.com/jpcedenog/gointercept)\n![Tests](https://github.com/jpcedenog/gointercept/workflows/Tests/badge.svg)\n\n\u003ca href=\"https://www.buymeacoffee.com/jpcedenog\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: auto !important;width: auto !important;\" \u003e\u003c/a\u003e\n\n### About GoIntercept\n\nA middleware layer allows developers to focus on the business logic when designing and implementing their core business logic. This way, additional functionality like authentication/authorization, input validation , serialization, etc. can be added in a modular and reusable way.\n\nWeb frameworks such as Echo, Spiral, Gin, among others, provide middleware functionality to wrap HTTP requests and thus provide additional features without polluting the core logic in the HTTP handler. \n\nGoIntercept is a simple but powerful middleware engine that simplifies the development of AWS Lambda functions implemented in Go.\n\n### Quick Example\n\nThe simple example below shows the power of GoIntercept:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"github.com/aws/aws-lambda-go/lambda\"\n\t\"github.com/jpcedenog/gointercept\"\n\t\"github.com/jpcedenog/gointercept/interceptors\"\n\t\"log\"\n)\n\ntype Input struct {\n\tContent string `json:\"content\"`\n\tValue   int    `json:\"value\"`\n}\n\ntype Output struct {\n\tStatus  string\n\tContent string\n}\n\n// Dummy function that succeeds or fails depending on the given input\nfunc SampleFunction(context context.Context, input Input) (*Output, error) {\n\tif input.Value%2 != 0 {\n\t\treturn nil, errors.New(\"passed incorrect value\")\n\t} else {\n\t\treturn \u0026Output{\n\t\t\tStatus:  \"Success!\",\n\t\t\tContent: input.Content,\n\t\t}, nil\n\t}\n}\n\nconst (\n\tschema = `{\n    \"$id\": \"https://qri.io/schema/\",\n    \"$comment\" : \"sample comment\",\n    \"title\": \"Input\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"content\": {\n            \"type\": \"string\"\n        },\n        \"value\": {\n            \"description\": \"The Value\",\n            \"type\": \"integer\",\n            \"minimum\": 0,\n            \"maximum\": 2\n        }\n    },\n    \"required\": [\"content\", \"value\"]\n  }`\n)\n\nfunc main() {\n\tlambda.Start(gointercept.This(SampleFunction).With(\n        interceptors.Notify(\"SampleFunction starts\", \"SampleFunction ends\"),\n        interceptors.AddHeaders(map[string]string{\"Content-Type\": \"application/json\", \"company-header1\": \"foo1\", \"company-header2\": \"foo2\"}),\n        interceptors.AddSecurityHeaders(),\n        interceptors.CreateAPIGatewayProxyResponse(\u0026interceptors.DefaultStatusCodes{Success: 200, Error: 400}),\n        interceptors.ValidateBodyJSONSchema(schema),\n        interceptors.NormalizeHTTPRequestHeaders(true),\n        interceptors.ParseBody(\u0026Input{}, false),\n\t))\n}\n```\n\n### Usage\n\nThe example above shows that GoIntercept wraps around an existing Lambda Handler seamlessly. It is designed to get out of the way and remove all the boilerplate related to trivial and repetitive operations, such as: Logging, response formatting, HTTP header creation, input parsing and validation, etc.\n \nThe steps below describe the process to use GoIntercept:\n\n1. Implement your Lambda Handler.\n2. Import the *gointercept* and *gointercept/interceptors* packages.\n3. In the *main()* function, wrap your Lambda handler with the *gointercept.This()* function.\n4. Add all the required interceptors with the *.With()* method. **New interceptors are being added on a regular basis!**\n\n#### Execution Order\n\nGoIntercept is based on the [onion middleware pattern](https://esbenp.github.io/2015/07/31/implementing-before-after-middleware/). This means that each interceptor specified in the *With()* method wraps around the subsequent interceptor on the list, or the Lambda Handler itself when the last interceptor is reached.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"Onion Middleware Pattern\" src=\"img/OnionPattern.png\"/\u003e\n\u003c/div\u003e\n\nThe sequence of interceptors, passed to the *.With()* method, specifies the order in which they are executed. This means that the last interceptor on the list runs just before the Lambda handler is executed . Additionally, each interceptor can contain at least one of three possible execution phases: *Before, After, and OnError.*\n\nThe *Before* phase runs before the following interceptor on the list, or the Lambda handler itself, runs. Note that in this phase the Lambda handler's response has not been created yet, so you will have access only to the request. \n\nThe *After* phase runs after the following interceptor on the list, or the Lambda handler itself, has run. Note that in this phase the Lambda handler's response has already been created and is fully available.\n\nAs an example, if three middlewares have been specified and each has a *Before* and *After* phases, the steps below present the expected execution order:\n\nExecution Step | Middleware | Phase\n-------------- | ---------- | -----\n1 | Middleware1 | Before\n2 | Middleware2 | Before\n3 | Middleware3 | Before\n4 | Lambda Handler | N/A\n5 | Middleware3 | After\n6 | Middleware2 | After\n7 | Middleware1 | After\n\n#### Error Handling\n\nOptionally, an interceptor can specify an *OnError* phase handler. This handler is triggered whenever an error is raised by the execution of any of the handler's phases(*Before* or *After*) or the Lambda handler itself.\n\nIf no *OnError* handler is specified and an error is raised, the error is simply passed as is to the parent handler (interceptor) or the method that called the Lambda handler.\n\n### Custom Interceptors\n\nCustom interceptors are simply instances of the *gointercept.Interceptor* struct. This struct allows to specify any of the phases executed by the interceptor which are, in turn, specified by the type *LambdaHandler*:\n\n```go\ntype LambdaHandler func(context.Context, interface{}) (interface{}, error)\n\ntype Interceptor struct {\n\tBefore  LambdaHandler\n\tAfter   LambdaHandler\n\tOnError ErrorHandler\n}\n```\n\nAll native interceptors are implemented as a function that returns an instance of *gointercept.Interceptor*. This offers the advantage of specifying configuration parameters that are needed by the interceptor (see the *.AddHeaders* interceptor in the example above).\n\n### Available Middlewares\n\nName | Phases | Description\n---- | ------ | -----------\nNotify | Before and After | Used for logging purposes. It prints the two given messages during the *Before* and *After* phases respectively.\nCreateAPIGatewayProxyResponse | After or OnError | Formats the output or error of the Lambda handler as an instance of [API Gateway Proxy Response](https://godoc.org/github.com/aws/aws-lambda-go/events#APIGatewayProxyResponse)\nAddHeaders | After | Adds the given HTTP headers (provided as key-value pairs) to the response. It converts the response to an APIGatewayProxyResponse if it is not already one\nParseBody | Before | Reads the JSON-encoded payload (request) and stores it in the value pointed to by its input\nAddSecurityHeaders | After | Adds the default security HTTP headers (provided as key-value pairs) to the response. It converts the response to an APIGatewayProxyResponse if it is not already one. These headers follow security best practices, similar to what is done by [HelmetJS](https://helmetjs.github.io/)\nValidateBodyJSONSchema | Before | Validates the payload against the given JSON schema. For more information check [qrio.io's JsonSchema](https://github.com/qri-io/jsonschema)\nNormalizeHTTPRequestHeaders | Before | Captures the headers (single and multi-value) sent in the API Gateway (HTTP) request and normalizes them to either an all-lowercase form or to their canonical form (content-type as opposed to Content-Type) based on the value of the given 'canonical' parameter.\n\n### Contributing\n\nEveryone is welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.\n\n### License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjpcedenog%2Fgointercept.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjpcedenog%2Fgointercept?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpcedenog%2Fgointercept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpcedenog%2Fgointercept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpcedenog%2Fgointercept/lists"}