Move ENV imports to config package
This commit is contained in:
@@ -3,7 +3,6 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
db "zardzul/music-index/sqlc"
|
||||
@@ -11,16 +10,11 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
func Connect() (*pgxpool.Pool, *db.Queries, error) {
|
||||
func Connect(databaseurl string) (*pgxpool.Pool, *db.Queries, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
databaseURL := os.Getenv("DATABASE_URL")
|
||||
if databaseURL == "" {
|
||||
panic("DATABASE_URL environment variable not set")
|
||||
}
|
||||
|
||||
pool, err := pgxpool.New(ctx, databaseURL)
|
||||
pool, err := pgxpool.New(ctx, databaseurl)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("create pool: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user