-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·49 lines (35 loc) · 1.02 KB
/
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
49
package main
import (
_ "embed"
"net/http"
"time"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
iago "github.com/sanojsubran/iago/pkg/iago"
)
//go:embed config.json
var cfg string
func main() {
r := mux.NewRouter()
var news iago.NewsHandler
news.Init()
sources := news.GetConfiguredSources(cfg)
go func() {
for {
for _, source := range sources {
err := news.UpdateFeed(source)
if err != nil {
logrus.Errorf("unable to fetch the data from %s at %v", source.Topic, time.Now().UTC())
}
}
time.Sleep(60 * time.Minute)
}
}()
header := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"})
methods := handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS"})
origins := handlers.AllowedOrigins([]string{"*"})
logrus.Info("Starting IAGO. Waiting for requests...")
r.HandleFunc("/", news.HandleNewsRequests)
logrus.Fatal(http.ListenAndServe(":8080", handlers.CORS(header, methods, origins)(r)))
}