-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (46 loc) · 1.05 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
package main
import (
"context"
"flag"
"log"
tgClient "tgbot/clients/telegram"
"tgbot/consumer/event-consumer"
"tgbot/events/telegram"
"tgbot/storage/sqlite"
)
const (
tgBotHost = "api.telegram.org"
sqliteStoragePath = "data/sqlite/storage.db"
batchSize = 100
)
func main() {
//s := files.New(storagePath)
s, err := sqlite.New(sqliteStoragePath)
if err != nil {
log.Fatal("can't connect to storage: ", err)
}
if err := s.Init(context.TODO()); err != nil {
log.Fatal("can't init storage: ", err)
}
eventsProcessor := telegram.New(
tgClient.New(tgBotHost, mustToken()),
s,
)
log.Print("service started")
consumer := event_consumer.New(eventsProcessor, eventsProcessor, batchSize)
if err := consumer.Start(); err != nil {
log.Fatal("service is stopped", err)
}
}
func mustToken() string {
token := flag.String(
"tg-bot-token",
"6347212376:AAH72WHstnnXd84DFI3aeZ93sBoLJR2FJ-A",
"token for access to telegram bot",
)
flag.Parse()
if *token == "" {
log.Fatal("token is not specified")
}
return *token
}