diff --git a/api/tests/apierr_test.go b/api/tests/apierr_test.go index 44e1b5201..7bd6ac3c7 100644 --- a/api/tests/apierr_test.go +++ b/api/tests/apierr_test.go @@ -3,11 +3,12 @@ package tests import ( "fmt" - "bisonai.com/orakl/api/apierr" - "bisonai.com/orakl/api/utils" "testing" "time" + "bisonai.com/orakl/api/apierr" + "bisonai.com/orakl/api/utils" + "github.com/joho/godotenv" "github.com/stretchr/testify/assert" ) @@ -38,11 +39,9 @@ func TestApiErr(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") apierr.Routes(v1) diff --git a/api/tests/chain_test.go b/api/tests/chain_test.go index 115bd8f57..b8a409362 100644 --- a/api/tests/chain_test.go +++ b/api/tests/chain_test.go @@ -1,11 +1,12 @@ package tests import ( - "bisonai.com/orakl/api/chain" - "bisonai.com/orakl/api/utils" "fmt" "testing" + "bisonai.com/orakl/api/chain" + "bisonai.com/orakl/api/utils" + "github.com/joho/godotenv" "github.com/stretchr/testify/assert" ) @@ -22,11 +23,9 @@ func TestChain(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") chain.Routes(v1) diff --git a/api/tests/listener_test.go b/api/tests/listener_test.go index ecb4e6fad..0924aea80 100644 --- a/api/tests/listener_test.go +++ b/api/tests/listener_test.go @@ -1,12 +1,13 @@ package tests import ( + "fmt" + "testing" + "bisonai.com/orakl/api/chain" "bisonai.com/orakl/api/listener" "bisonai.com/orakl/api/service" "bisonai.com/orakl/api/utils" - "fmt" - "testing" "github.com/joho/godotenv" "github.com/stretchr/testify/assert" @@ -36,11 +37,9 @@ func TestListener(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") chain.Routes(v1) diff --git a/api/tests/proxy_test.go b/api/tests/proxy_test.go index 7899f4be5..616b4dc2f 100644 --- a/api/tests/proxy_test.go +++ b/api/tests/proxy_test.go @@ -1,11 +1,12 @@ package tests import ( - "bisonai.com/orakl/api/proxy" - "bisonai.com/orakl/api/utils" "fmt" "testing" + "bisonai.com/orakl/api/proxy" + "bisonai.com/orakl/api/utils" + "github.com/joho/godotenv" "github.com/stretchr/testify/assert" ) @@ -33,11 +34,9 @@ func TestProxy(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") proxy.Routes(v1) diff --git a/api/tests/reporter_test.go b/api/tests/reporter_test.go index 2538c034a..867e884ca 100644 --- a/api/tests/reporter_test.go +++ b/api/tests/reporter_test.go @@ -1,12 +1,13 @@ package tests import ( + "fmt" + "testing" + "bisonai.com/orakl/api/chain" "bisonai.com/orakl/api/reporter" "bisonai.com/orakl/api/service" "bisonai.com/orakl/api/utils" - "fmt" - "testing" "github.com/joho/godotenv" "github.com/stretchr/testify/assert" @@ -38,11 +39,9 @@ func TestReporter(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") chain.Routes(v1) diff --git a/api/tests/service_test.go b/api/tests/service_test.go index a7f485cdc..61d431aa0 100644 --- a/api/tests/service_test.go +++ b/api/tests/service_test.go @@ -1,11 +1,12 @@ package tests import ( - "bisonai.com/orakl/api/service" - "bisonai.com/orakl/api/utils" "fmt" "testing" + "bisonai.com/orakl/api/service" + "bisonai.com/orakl/api/utils" + "github.com/joho/godotenv" "github.com/stretchr/testify/assert" ) @@ -22,11 +23,9 @@ func TestService(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") service.Routes(v1) diff --git a/api/tests/vrf_test.go b/api/tests/vrf_test.go index 451a3fcf3..d87be7e0a 100644 --- a/api/tests/vrf_test.go +++ b/api/tests/vrf_test.go @@ -1,11 +1,12 @@ package tests import ( + "fmt" + "testing" + "bisonai.com/orakl/api/chain" "bisonai.com/orakl/api/utils" "bisonai.com/orakl/api/vrf" - "fmt" - "testing" "github.com/joho/godotenv" "github.com/stretchr/testify/assert" @@ -39,11 +40,9 @@ func TestVrf(t *testing.T) { appConfig, _ := utils.Setup() pgxClient := appConfig.Postgres - redisClient := appConfig.Redis app := appConfig.App defer pgxClient.Close() - defer redisClient.Close() v1 := app.Group("/api/v1") vrf.Routes(v1) chain.Routes(v1) diff --git a/api/utils/utils.go b/api/utils/utils.go index 952e4f613..c1c4a054d 100644 --- a/api/utils/utils.go +++ b/api/utils/utils.go @@ -22,12 +22,10 @@ import ( "github.com/gofiber/fiber/v2/middleware/recover" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgxpool" - "github.com/redis/go-redis/v9" ) type AppConfig struct { Postgres *pgxpool.Pool - Redis *redis.Conn App *fiber.App } @@ -50,33 +48,6 @@ func GetPgx(c *fiber.Ctx) (*pgxpool.Pool, error) { } } -func GetRdb(c *fiber.Ctx) (redis.Conn, error) { - con, ok := c.Locals("rdb").(redis.Conn) - if !ok { - return con, errors.New("failed to get rdbConn") - } else { - return con, nil - } -} - -func SetRedis(c *fiber.Ctx, key string, value string) error { - redisConn, err := GetRdb(c) - if err != nil { - return err - } - - return redisConn.Set(c.Context(), key, value, 0).Err() -} - -func GetRedis(c *fiber.Ctx, key string) (string, error) { - redisConn, err := GetRdb(c) - if err != nil { - return "", err - } - - return redisConn.Get(c.Context(), key).Result() -} - func RawQueryWithoutReturn(c *fiber.Ctx, query string, args map[string]any) error { pgxPool, err := GetPgx(c) if err != nil { @@ -149,14 +120,6 @@ func Setup(options ...string) (AppConfig, error) { if pgxError != nil { return appConfig, pgxError } - // redis connect - rdb := redis.NewClient(&redis.Options{ - Addr: config["REDIS_HOST"].(string) + ":" + config["REDIS_PORT"].(string), - }).Conn() - _, rdbErr := rdb.Ping(context.Background()).Result() - if rdbErr != nil { - return appConfig, rdbErr - } testing, err := strconv.ParseBool(config["TEST_MODE"].(string)) if err != nil { @@ -178,7 +141,6 @@ func Setup(options ...string) (AppConfig, error) { app.Use(cors.New()) app.Use(func(c *fiber.Ctx) error { - c.Locals("rdb", *rdb) c.Locals("pgxConn", pgxPool) c.Locals("testing", testing) return c.Next() @@ -186,7 +148,6 @@ func Setup(options ...string) (AppConfig, error) { appConfig = AppConfig{ Postgres: pgxPool, - Redis: rdb, App: app, } return appConfig, nil