-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
45 lines (43 loc) · 1.06 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
package main
import (
"context"
"file2url/api"
"file2url/bot"
"file2url/config"
"file2url/database"
"file2url/shared"
"fmt"
"github.com/gotd/td/session"
"github.com/gotd/td/telegram"
"log"
"os/signal"
"syscall"
)
func main() {
// Load config
var err error
config.LoadConfig()
shared.Database, err = database.LoadDatabaseFromEnv()
if err != nil {
log.Fatalln("cannot open the database: ", err)
}
defer func() {
if err := shared.Database.Close(); err != nil {
log.Println("cannot close the database: ", err)
}
}()
// Load the bot
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
stopChannel := make(chan struct{})
go api.StartWebserver(stopChannel)
fmt.Println("file2url-go version " + config.Version)
err = telegram.BotFromEnvironment(ctx,
telegram.Options{SessionStorage: &session.FileStorage{Path: "session"}, UpdateHandler: shared.Dispatcher},
bot.RunBot,
telegram.RunUntilCanceled)
stopChannel <- struct{}{}
if err != nil {
log.Fatalln(err)
}
<-stopChannel // wait until the server is down
}