-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (39 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package fume
import (
"context"
"log"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
fiberadapter "github.com/awslabs/aws-lambda-go-api-proxy/fiber"
// fiberadapter "github.com/fumeapp/fiber/adapter"
"github.com/gofiber/fiber/v2"
)
var fiberLambda *fiberadapter.FiberLambda
type Options struct {
// optional - hostname to listen on (default: localhost)
Host string
// optional - port to run on (default: 8000)
Port string
}
func Start(app *fiber.App, options Options) {
defaults := &Options{
Host: "localhost",
Port: "8000",
}
if options.Port != "" {
defaults.Port = options.Port
}
if options.Host != "" {
defaults.Host = options.Host
}
if os.Getenv("_HANDLER") != "" {
fiberLambda = fiberadapter.New(app)
lambda.Start(Handler)
} else {
log.Fatal(app.Listen(defaults.Host + ":" + defaults.Port))
}
}
func Handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
return fiberLambda.ProxyWithContextV2(ctx, req)
}