-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_lambda.go
63 lines (52 loc) · 1.38 KB
/
main_lambda.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
56
57
58
59
60
61
62
63
//go:build awslambda
// +build awslambda
package main
import (
"context"
"encoding/base64"
"log"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type Output struct {
StatusCode int `json:"statusCode"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded"`
}
type MyEvent struct {
Name string `json:"name"`
}
func HandleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (Output, error) {
name := request.QueryStringParameters["name"]
id := request.QueryStringParameters["id"]
mediaType := request.QueryStringParameters["type"]
var image []byte
log.Println("Name:", name)
log.Println("Id:", id)
log.Println("MediaType:", mediaType)
if name == "" && id == "" && mediaType == "" {
image = getDefaultImage()
log.Println("No input, returning default image")
} else {
im, ok := getImage(name, id, mediaType)
if ok {
image = im
log.Println("Found image")
} else {
image = getDefaultImage()
log.Println("No image found, returning default image")
}
}
return Output{
StatusCode: 200,
Headers: map[string]string{
"Content-Type": "image/jpeg",
},
Body: base64.StdEncoding.EncodeToString(image),
IsBase64Encoded: true,
}, nil
}
func main() {
lambda.Start(HandleRequest)
}