-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 1023 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
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type WeatherResponse struct {
Weather string `json:"weather"`
Timestamp int64 `json:"timestamp"`
}
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// Retrieve dummy weather information
weather := "Sunny"
// Get current timestamp
timestamp := time.Now().Unix()
// Create the response object
response := WeatherResponse{
Weather: weather,
Timestamp: timestamp,
}
// Convert the response to JSON
responseJSON, err := json.Marshal(response)
if err != nil {
return events.APIGatewayProxyResponse{StatusCode: http.StatusInternalServerError}, fmt.Errorf("failed to marshal response: %v", err)
}
// Return the response
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Body: string(responseJSON),
}, nil
}
func main() {
lambda.Start(handler)
}