-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
48 lines (39 loc) · 828 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
48
package main
import (
"errors"
"fmt"
"os"
"github.com/aws/aws-lambda-go/lambda"
"github.com/circa10a/go-aws-news/providers"
log "github.com/sirupsen/logrus"
"github.com/circa10a/go-aws-news/news"
)
func main() {
if os.Getenv("AWS_EXECUTION_ENV") == "AWS_Lambda_go1.x" {
lambda.Start(mainExec)
} else {
err := mainExec()
if err != nil {
log.Fatal(err)
}
}
}
func mainExec() error {
news, err := news.Yesterday()
if err != nil {
return err
}
if len(news) == 0 {
log.Info("No news fetched. Skipping notifications.")
return nil
}
providers := providers.GetProviders()
if len(providers) == 0 {
return errors.New("no providers enabled. see configuration")
}
for _, p := range providers {
log.Info(fmt.Sprintf("[%v] Provider registered", p.GetName()))
p.Notify(news)
}
return nil
}