Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/renanbastos93/go-function-simulator
Run functions locally with Go, like Aws Lambda
https://github.com/renanbastos93/go-function-simulator
cloud edge function go lambda
Last synced: 18 days ago
JSON representation
Run functions locally with Go, like Aws Lambda
- Host: GitHub
- URL: https://github.com/renanbastos93/go-function-simulator
- Owner: renanbastos93
- License: mit
- Created: 2024-09-03T13:41:17.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-03T21:38:12.000Z (2 months ago)
- Last Synced: 2024-10-06T16:41:32.408Z (about 1 month ago)
- Topics: cloud, edge, function, go, lambda
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-function-simulator
Run functions locally with Go.## Overview
It is a tool designed to help you run and test your functions locally with Go. It supports various HTTP request types and frameworks such as Fiber, Gorilla Mux, and Chi. This allows you to simulate and debug AWS Lambda functions or any HTTP-based services on your local machine.## Features
- **Support for Multiple Request Types:** Handle and simulate HTTP requests using different frameworks.
- **Flexible Conversion:** Convert HTTP requests to AWS API Gateway proxy requests and vice versa.
- **Easy Integration:** Seamlessly integrate with your existing Go projects.## Installation
To install `go-function-simulator`, you can use Go modules to add it to your project:
```bash
$ go get github.com/yourusername/go-function-simulator
```## Usage Fiber
```go
package mainimport (
"github.com/gofiber/fiber/v2"
"github.com/renanbastos93/go-function-simulator/pkg/http"
)func main() {
app := fiber.New()app.Get("/path/:id", func(c *fiber.Ctx) error {
apiGatewayProxyRequest := http.ConvertHTTPRequestToAPIGatewayProxyRequest(c.Context(), c)
fmt.Println("API Gateway Proxy Request:", apiGatewayProxyRequest)
// call your lambda function
// like this: usecase.Lambda(ctx, apiGatewayProxyRequest)
return c.SendStatus(fiber.StatusOK)
})_ = app.Listen(":3000")
}```
## Usage Gorilla Mux
```go
package mainimport (
"context"
"fmt"stdHttp "net/http"
"github.com/gorilla/mux"
"github.com/renanbastos93/go-function-simulator/pkg/http"
)func main() {
r := mux.NewRouter()
r.HandleFunc("/path/{id}", func(w stdHttp.ResponseWriter, r *stdHttp.Request) {
apiGatewayProxyRequest := http.ConvertHTTPRequestToAPIGatewayProxyRequest(context.Background(), r)
fmt.Println("API Gateway Proxy Request:", apiGatewayProxyRequest)
/// call your lambda function
// like this: usecase.Lambda(ctx, apiGatewayProxyRequest)
w.WriteHeader(stdHttp.StatusOK)
})_ = stdHttp.ListenAndServe(":3000", r)
}
```