-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (36 loc) · 896 Bytes
/
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
package main
import (
"context"
"github.com/go-redis/redis/v8"
"github.com/sirupsen/logrus"
"os"
"strconv"
)
const (
envPort = "PORT"
envRedisAddr = "REDIS_ADDR"
envRedisPass = "REDIS_PASSWORD"
envRedisDB = "REDIS_DB"
)
func main() {
logger := logrus.New()
logger.SetLevel(logrus.TraceLevel)
redisDB, err := strconv.Atoi(os.Getenv(envRedisDB))
if err != nil {
logger.WithError(err).Panic("REDIS_DB must be an integer")
}
client := redis.NewClient(&redis.Options{
Addr: os.Getenv(envRedisAddr),
Password: os.Getenv(envRedisPass),
DB: redisDB,
})
_, err = client.Ping(context.Background()).Result()
if err != nil {
logger.WithError(err).Panic("Error connecting to redis")
}
logger.Infof("Connected with redis: %s", client)
server := NewServer(logger, client)
server.Listen()
<-server.connClose
logger.Info("Server shutdown complete")
}