-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (56 loc) · 1.56 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"log"
"net/http"
authClient "github.com/hashtock/auth/client"
"github.com/nats-io/nats"
"github.com/hashtock/tracker/conf"
"github.com/hashtock/tracker/core"
"github.com/hashtock/tracker/listener"
"github.com/hashtock/tracker/storage"
"github.com/hashtock/tracker/webapi"
)
func main() {
cfg := conf.GetConfig()
cfg.General.Timeout = 0 // No timeout
nc, err := nats.Connect(cfg.General.NATS)
if err != nil {
log.Panicln(err)
}
msgConnection, err := nats.NewEncodedConn(nc, "json")
if err != nil {
log.Panicln(err)
}
defer msgConnection.Close()
counter, err := storage.NewMongoCounter(cfg.General.DB, cfg.General.SampingTime)
if err != nil {
log.Panicln(err)
}
tagNames, err := core.TagNames(counter)
if err != nil {
log.Panicln(err)
}
noticiator := NewMsgNoticiator(counter, msgConnection)
listenerOptions := listener.Options{
TagUpdateTime: cfg.General.TagUpdateTime,
SampingTime: cfg.General.SampingTime,
Verbose: true,
Notificator: noticiator,
}
twitterListener := listener.NewTwitterListener(tagNames, cfg.General.Timeout, cfg.General.UpdateTime, cfg.Auth)
go listener.Listen(twitterListener, counter, listenerOptions)
whoClient, whoErr := authClient.NewClient(cfg.General.AuthAddress)
if whoErr != nil {
log.Panicln(err)
}
handlerOptions := webapi.Options{
Serializer: new(webapi.WebAPISerializer),
Counter: counter,
WhoClient: whoClient,
}
handler := webapi.Handlers(handlerOptions)
err = http.ListenAndServe(cfg.General.ServeAddress, handler)
if err != nil {
log.Panicln(err)
}
}