-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (49 loc) · 1.11 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
package main
import (
"context"
"flag"
"log"
"os"
tgClient "github.com/yellowpuki/tg-bot/clients/telegram"
event_consumer "github.com/yellowpuki/tg-bot/consumer/event-consumer"
"github.com/yellowpuki/tg-bot/events/telegram"
"github.com/yellowpuki/tg-bot/storage/sqlite"
)
const (
tgBotHost = "api.telegram.org"
filesStoragePath = "data/files"
sqlliteStoragePath = "data/sqlite/storage.db"
batchSize = 100
)
func main() {
//s := files.New(storagePath)
s, err := sqlite.New(sqlliteStoragePath)
if err != nil {
log.Fatal(err)
}
if err := s.Init(context.TODO()); err != nil {
log.Fatal("can't init storage", err)
}
eventProcessor := telegram.New(
tgClient.New(tgBotHost, os.Getenv("TOKEN")),
s,
)
log.Print("service started")
consumer := event_consumer.New(eventProcessor, eventProcessor, batchSize)
if err := consumer.Start(); err != nil {
log.Fatal(err)
}
}
// mustToken ...
func mustToken() string {
token := flag.String(
"t",
"",
"token for access to telegram bot",
)
flag.Parse()
if *token == "" {
log.Fatal("token is not specified")
}
return *token
}