/
main.go
55 lines (47 loc) · 1.08 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
49
50
51
52
53
54
55
package main
import (
"context"
"encoding/json"
"io"
"path/filepath"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/grokify/go-awslambda"
)
type customStruct struct {
Content string
FileName string
FileExtension string
}
func handleRequest(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
res := events.APIGatewayProxyResponse{}
r, err := awslambda.NewReaderMultipart(req)
if err != nil {
return res, err
}
part, err := r.NextPart()
if err != nil {
return res, err
}
content, err := io.ReadAll(part)
if err != nil {
return res, err
}
custom := customStruct{
Content: string(content),
FileName: part.FileName(),
FileExtension: filepath.Ext(part.FileName())}
customBytes, err := json.Marshal(custom)
if err != nil {
return res, err
}
res = events.APIGatewayProxyResponse{
StatusCode: 200,
Headers: map[string]string{
"Content-Type": "application/json"},
Body: string(customBytes)}
return res, nil
}
func main() {
lambda.Start(handleRequest)
}