This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
58 lines (46 loc) · 1.51 KB
/
init.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
package main
import (
"github.com/gorilla/mux"
"github.com/shitpostingio/analysis-api/api/cache"
"github.com/shitpostingio/analysis-api/api/database"
"github.com/shitpostingio/analysis-api/api/handler"
"github.com/shitpostingio/analysis-api/configuration"
"github.com/shitpostingio/analysis-commons/downloader"
log "github.com/sirupsen/logrus"
"os"
)
func init() {
setEnvVars()
cfg, err := configuration.Load(cfgPath)
if err != nil {
log.Fatal("Unable to load configuration", err)
}
if !cfg.Testing {
database.Connect(&cfg.Database)
} else {
log.SetLevel(log.DebugLevel)
}
err = cache.NewFingerprintRedisClient(cfg.Redis.Address, "", cfg.Redis.FingerprintDatabase)
if err != nil {
log.Fatal("Unable to connect to fingerprint cache", err)
}
err = cache.NewNSFWRedisClient(cfg.Redis.Address, "", cfg.Redis.NSFWDatabase)
if err != nil {
log.Fatal("Unable to connect to nsfw cache", err)
}
telegramDownloader := &downloader.TelegramDownloader{MaxDownloadSize: cfg.MaxDownloadSize}
telegramHandler = handler.New(cfg.Testing, cfg.NSFWEndpoint, cfg.FingerprintEndpoint, cfg.GibberishEndpoint, telegramDownloader)
directDownloader := &downloader.DirectDownloader{MaxDownloadSize: cfg.MaxDownloadSize}
directHandler = handler.New(cfg.Testing, cfg.NSFWEndpoint, cfg.FingerprintEndpoint, cfg.GibberishEndpoint, directDownloader)
r = mux.NewRouter()
}
func setEnvVars() {
cp := os.Getenv(cfgPathKey)
if cp != "" {
cfgPath = cp
}
add := os.Getenv(bindAddressKey)
if add != "" {
bindAddress = add
}
}