forked from rssnyder/discord-stock-ticker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (67 loc) · 1.88 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
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"os"
"sync"
"github.com/go-redis/redis/v8"
"github.com/namsral/flag"
log "github.com/sirupsen/logrus"
)
var (
logger = log.New()
buildVersion = "development"
address *string
db *string
frequency *int
redisAddress *string
redisPassword *string
redisDB *int
cache *bool
managed *bool
version *bool
rdb *redis.Client
ctx context.Context
)
func init() {
logLevel := flag.Int("logLevel", 0, "defines the log level: 0=INFO 1=DEBUG")
address = flag.String("address", "0.0.0.0:8080", "address:port to bind http server to")
db = flag.String("db", "", "file to store tickers in")
frequency = flag.Int("frequency", 0, "set frequency for all tickers")
redisAddress = flag.String("redisAddress", "localhost:6379", "address:port for redis server")
redisPassword = flag.String("redisPassword", "", "redis password")
redisDB = flag.Int("redisDB", 0, "redis db to use")
cache = flag.Bool("cache", false, "enable cache for coingecko")
managed = flag.Bool("managed", false, "forcefully keep db and discord updated with bot values")
version = flag.Bool("version", false, "print version")
flag.Parse()
// init logger
logger.Out = os.Stdout
switch *logLevel {
case 0:
logger.SetLevel(log.InfoLevel)
default:
logger.SetLevel(log.DebugLevel)
}
}
func main() {
var wg sync.WaitGroup
if *version {
logger.Infof("discord-stock-ticker@%s\n", buildVersion)
return
}
logger.Infof("Running discord-stock-ticker version %s...", buildVersion)
// Redis is used a an optional cache for coingecko data
if *cache {
rdb = redis.NewClient(&redis.Options{
Addr: *redisAddress,
Password: *redisPassword,
DB: *redisDB,
})
ctx = context.Background()
}
// Create the bot manager
wg.Add(1)
NewManager(*address, *db, tickerCount, rdb, ctx)
// wait forever
wg.Wait()
}