-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
48 lines (41 loc) · 1.19 KB
/
test.go
File metadata and controls
48 lines (41 loc) · 1.19 KB
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
//https://www.alexedwards.net/blog/serverless-api-with-go-and-aws-lambda
package main
import (
"fmt"
"encoding/json"
"context"
"net/http"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/events"
)
// Response risposta
type Response struct {
StatusCode int `json:"statusCode"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
isBase64Encoded bool
}
// Testo il body
type Testo struct {
Hello string
}
// MyEvent per le cose che arrivano
type MyEvent struct {
Name string `json:"name"`
}
// HandleRequest il return
func HandleRequest(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
nome := new(MyEvent)
err := json.Unmarshal([]byte(req.Body), nome)
testo := &Testo{
Hello: fmt.Sprintf("Dr %s", nome.Name),
};
body, err := json.Marshal(testo)
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Body: string(body),
}, err
}
func main() {
lambda.Start(HandleRequest)
}