-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnews.go
46 lines (41 loc) · 1.13 KB
/
news.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
package main
// Ensure the user is notified in the event there is no news/aws site is down
func defaultNewsStatement(n []CarouselItem) string {
if len(n) == 0 {
return "No cloud computing news yet."
}
return "Here's the latest cloud computing news."
}
// There needs to be a minimum of two items in the carousel or user gets an error
func defaultNewsItem() []CarouselItem {
var newsItems []CarouselItem
for i := 1; i <= 2; i++ {
newsItems = append(newsItems, CarouselItem{
Title: "No recent news",
Description: "Check back soon",
OpenURLAction: OpenURLAction{
URL: "https://aws.amazon.com/new",
},
})
}
return newsItems
}
// Get news items from cache and generate list of structs for the JSON response
func getNewsListItems() []CarouselItem {
newsItems := make([]CarouselItem, 0)
news := getNewsFromCache()
if len(news) == 0 {
return defaultNewsItem()
}
for _, newsItem := range news {
itemInfo := CarouselItem{
Title: newsItem.Title,
Description: newsItem.PostDate,
OpenURLAction: OpenURLAction{
URL: newsItem.Link,
},
}
newsItems = append(newsItems, itemInfo)
}
return newsItems
}