Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(API) Remove unused redis reference #1834

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions api/tests/apierr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions api/tests/chain_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions api/tests/listener_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions api/tests/proxy_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions api/tests/reporter_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions api/tests/service_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions api/tests/vrf_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 0 additions & 39 deletions api/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -178,15 +141,13 @@ 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()
})

appConfig = AppConfig{
Postgres: pgxPool,
Redis: rdb,
App: app,
}
return appConfig, nil
Expand Down
Loading