forked from anomalyco/sst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.go
More file actions
36 lines (28 loc) · 760 Bytes
/
Copy pathupdate.go
File metadata and controls
36 lines (28 loc) · 760 Bytes
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
package main
import (
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/serverless-stack/examples/rest-api-go/db"
)
func Handler(request events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) {
var notes = db.Notes()
var note = notes[request.PathParameters["id"]]
if note == nil {
return events.APIGatewayProxyResponse{
Body: `{"error":true}`,
StatusCode: 404,
}, nil
}
var body map[string]string
_ = json.Unmarshal([]byte(request.Body), &body)
note["content"] = body["content"]
response, _ := json.Marshal(note)
return events.APIGatewayProxyResponse{
Body: string(response),
StatusCode: 200,
}, nil
}
func main() {
lambda.Start(Handler)
}