-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (35 loc) · 807 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
package main
import (
"context"
"log/slog"
"os"
gowebly "github.com/gowebly/helpers"
"github.com/joho/godotenv"
"github.com/redis/go-redis/v9"
)
var redisClient *redis.Client
func init() {
if err := godotenv.Load(); err != nil {
slog.Error("Error loading .env file: %v", err)
os.Exit(1)
}
ctx := context.Background()
redisHost := gowebly.Getenv("REDIS_URL", "")
opts, err := redis.ParseURL(redisHost)
if err != nil {
slog.Error("Error parsing URL to redis: %v", err)
os.Exit(1)
}
redisClient = redis.NewClient(opts)
_, err = redisClient.Ping(ctx).Result()
if err != nil {
slog.Error("Error trying to ping redis: %v", err)
os.Exit(1)
}
}
func main() {
if err := runServer(); err != nil {
slog.Error("Failed to start server!", "details", err.Error())
os.Exit(1)
}
}