feat(api): allow not having a redis connection for development

This commit is contained in:
Sam 2022-11-20 03:44:20 +01:00
parent 683d61bd82
commit b9101e260b
1 changed files with 9 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"codeberg.org/u1f320/pronouns.cc/backend/log"
"emperror.dev/errors" "emperror.dev/errors"
"github.com/Masterminds/squirrel" "github.com/Masterminds/squirrel"
"github.com/jackc/pgx/v4/pgxpool" "github.com/jackc/pgx/v4/pgxpool"
@ -33,9 +34,14 @@ func New() (*DB, error) {
return nil, errors.Wrap(err, "creating postgres client") return nil, errors.Wrap(err, "creating postgres client")
} }
redis, err := (&radix.PoolConfig{}).New(context.Background(), "tcp", os.Getenv("REDIS")) var redis radix.Client
if err != nil { if os.Getenv("REDIS") != "" {
return nil, errors.Wrap(err, "creating redis client") redis, err = (&radix.PoolConfig{}).New(context.Background(), "tcp", os.Getenv("REDIS"))
if err != nil {
return nil, errors.Wrap(err, "creating redis client")
}
} else {
log.Warn("$REDIS was empty! ANY FUNCTIONALITY using redis will CRASH the server")
} }
minioClient, err := minio.New(os.Getenv("MINIO_ENDPOINT"), &minio.Options{ minioClient, err := minio.New(os.Getenv("MINIO_ENDPOINT"), &minio.Options{