-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
37 lines (28 loc) · 648 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
package main
import (
"errors"
"os"
"time"
"github.com/SlyMarbo/rss"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type Post struct {
URL string `json:"url"`
Title string `json:"title"`
Date time.Time `json:"date"`
}
func handleRequest(req events.APIGatewayProxyRequest) (interface{}, error) {
feed, err := rss.Fetch(os.Getenv("URL"))
if err != nil {
return nil, errors.New("Cannot fetch RSS feed")
}
list := []Post{}
for _, item := range feed.Items {
list = append(list, Post{item.Link, item.Title, item.Date})
}
return list, nil
}
func main() {
lambda.Start(handleRequest)
}