Fixed bug with nil global.RedisClient
This commit is contained in:
parent
98bcedce3e
commit
b6feee67f0
7
init.go
7
init.go
|
@ -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")
|
||||
}
|
||||
|
|
8
main.go
8
main.go
|
@ -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)),
|
||||
|
|
Loading…
Reference in New Issue