Fixed bug with nil global.RedisClient

This commit is contained in:
vysion 2021-09-08 16:59:06 -07:00
parent 98bcedce3e
commit b6feee67f0
2 changed files with 4 additions and 11 deletions

View File

@ -16,6 +16,7 @@ const (
)
func init() {
log.Print("* Tytanium " + global.Version + "\n\n")
initConfiguration()
checkStorage()
initRedis()
@ -80,20 +81,20 @@ func checkStorage() {
}
func initRedis() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
redisClient := redis.NewClient(&redis.Options{
global.RedisClient = redis.NewClient(&redis.Options{
Addr: global.Configuration.Redis.URI,
Password: global.Configuration.Redis.Password,
DB: int(global.Configuration.Redis.DB),
})
status := redisClient.Ping(ctx).Err()
status := global.RedisClient.Ping(ctx).Err()
if status != nil {
cancel()
log.Fatalf("Could not ping Redis database, %v", status.Error())
}
cancel()
log.Println("Redis connection established")
}

View File

@ -3,7 +3,6 @@ package main
import (
"context"
_ "embed"
"github.com/spf13/viper"
"github.com/valyala/fasthttp"
"github.com/vysiondev/tytanium/global"
"github.com/vysiondev/tytanium/middleware"
@ -16,13 +15,6 @@ import (
)
func main() {
log.Print("* Tytanium " + global.Version + "\n\n")
viper.SetConfigName("config")
viper.AddConfigPath("./conf/")
viper.AutomaticEnv()
viper.SetConfigType("yml")
s := &fasthttp.Server{
ErrorHandler: nil,
Handler: middleware.HandleCORS(middleware.LimitPath(middleware.HandleHTTPRequest)),