-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
35 lines (30 loc) · 989 Bytes
/
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
package main
import (
"context"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"log"
)
type handlerFunc func(context.Context, events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
// the extra set of instructions
// things to be done before running the business logic
func logging(f handlerFunc) handlerFunc {
return func(ctx context.Context, r events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
log.Printf("remote_addr: %s", r.RequestContext.Identity.SourceIP)
return f(ctx, r)
}
}
// the business logic
// we could imagine here is defined the codebase core capability
func handle(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return events.APIGatewayProxyResponse{
Body: "i'm an app",
StatusCode: 200,
Headers: map[string] string {
"Content-Type": "application/json",
},
}, nil
}
func main() {
lambda.Start(logging(handle) )
}