feat(auth): implement user registration endpoint
This commit is contained in:
30
internal/database/postgres.go
Normal file
30
internal/database/postgres.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
_ "github.com/jackc/pgx/v5/stdlib" // Регистрируем pgx драйвер
|
||||
)
|
||||
|
||||
// Connect устанавливает соединение с базой данных PostgreSQL
|
||||
func Connect() *sql.DB {
|
||||
connStr := os.Getenv("DATABASE_URL")
|
||||
if connStr == "" {
|
||||
log.Fatal("DATABASE_URL environment variable is not set")
|
||||
}
|
||||
|
||||
db, err := sql.Open("pgx", connStr)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to connect to database: %v\n", err)
|
||||
}
|
||||
|
||||
// Проверяем, что соединение действительно установлено
|
||||
if err = db.Ping(); err != nil {
|
||||
log.Fatalf("Unable to ping database: %v\n", err)
|
||||
}
|
||||
|
||||
log.Println("Successfully connected to PostgreSQL!")
|
||||
return db
|
||||
}
|
||||
Reference in New Issue
Block a user