Сталкиваюсь с таким кодом ошибки , уже забивал в gpt он не может помочь выдает то что у меня написано правильно
2025-03-03 11:01:25 app-1 | 2025/03/03 08:01:25 Unable to connect to database:failed to connect to `user=postgres database=postgres`: /tmp/.s.PGSQL.5432 (/tmp): dial error: dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory
2025-03-03 11:32:36 2025/03/03 08:32:36 Unable to connect to database:failed to connect to `user=postgres database=postgres`: /tmp/.s.PGSQL.5432 (/tmp): dial error: dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory
такую же ошибку и выдает
"github.com/RUST-GOLANG/2025-q1-practice.git/config"
"github.com/RUST-GOLANG/2025-q1-practice.git/internal/routes"
"github.com/gorilla/mux"
"github.com/jackc/pgx/v5" // Импортируем pgx для работы с PostgreSQL
)
func main() {
cfg := config.LoadConfig()
// Замените 'your_password' и 'your_database' на ваши реальные данные
databaseURL := "user=postgres password=Ishtaev73 dbname=postgres sslmode=disable"
// Подключение к базе данных
conn, err := pgx.Connect(context.Background(), databaseURL)
if err != nil {
log.Fatal("Unable to connect to database:", err)
}
defer conn.Close(context.Background()) // Передаем контекст в Close()
fmt.Println("Successfully connected to the database!")
// Регистрация маршрутов
r := mux.NewRouter()
routes.RegisterRoutes(r, conn)
// Connect устанавливает соединение с базой данных PostgreSQL
func Connect(databaseURL string) *pgx.Conn {
// Проверка и добавление sslmode=disable, если это необходимо
if !containsSSLMode(databaseURL) {
databaseURL += " sslmode=disable"
}
conn, err := pgx.Connect(context.Background(), databaseURL)
if err != nil {
log.Fatal("Unable to connect to database:", err)
}
return conn
}
// containsSSLMode проверяет, содержит ли строка подключения параметр sslmode
func containsSSLMode(databaseURL string) bool {
return strings.Contains(databaseURL, "sslmode=")
}
config.go
package config
import (
"os"
)
type Config struct {
ServerAddress string
DatabaseURL string
}