mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-25 23:02:22 +02:00
сделал postgres_pgxpool
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ManyakRus/starter/constants"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/port_checker"
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -141,7 +142,7 @@ func GetConnectionString(ApplicationName string) string {
|
||||
dsn += "user=" + Settings.DB_USER + " "
|
||||
dsn += "password=" + Settings.DB_PASSWORD + " "
|
||||
dsn += "dbname=" + Settings.DB_NAME + " "
|
||||
dsn += "port=" + Settings.DB_PORT + " sslmode=disable TimeZone=UTC "
|
||||
dsn += "port=" + Settings.DB_PORT + " sslmode=disable TimeZone=" + constants.TIME_ZONE + " "
|
||||
dsn += "application_name=" + ApplicationName
|
||||
|
||||
return dsn
|
||||
@@ -380,31 +381,31 @@ loop:
|
||||
break loop
|
||||
case <-ticker.C:
|
||||
|
||||
//ping в базе данных
|
||||
mutex_Connect.RLock() //race
|
||||
//err = GetConnection().Ping(ctx) //ping делать нельзя т.к. data race
|
||||
err = Ping_err(ctx)
|
||||
mutex_Connect.RUnlock()
|
||||
if err != nil {
|
||||
switch err.Error() {
|
||||
case TextConnBusy:
|
||||
{
|
||||
log.Warn("postgres_pgx Ping() warning: ", err)
|
||||
}
|
||||
default:
|
||||
{
|
||||
NeedReconnect = true
|
||||
log.Error("postgres_pgx Ping() error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
//IsClosed
|
||||
if GetConnection().IsClosed() == true {
|
||||
NeedReconnect = true
|
||||
log.Error("postgres_pgx error: IsClosed() = true")
|
||||
}
|
||||
}
|
||||
////ping в базе данных
|
||||
//mutex_Connect.RLock() //race
|
||||
////err = GetConnection().Ping(ctx) //ping делать нельзя т.к. data race
|
||||
//err = Ping_err(ctx)
|
||||
//mutex_Connect.RUnlock()
|
||||
//if err != nil {
|
||||
// switch err.Error() {
|
||||
// case TextConnBusy:
|
||||
// {
|
||||
// log.Warn("postgres_pgx Ping() warning: ", err)
|
||||
// }
|
||||
// default:
|
||||
// {
|
||||
// NeedReconnect = true
|
||||
// log.Error("postgres_pgx Ping() error: ", err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//} else {
|
||||
// //IsClosed
|
||||
// if GetConnection().IsClosed() == true {
|
||||
// NeedReconnect = true
|
||||
// log.Error("postgres_pgx error: IsClosed() = true")
|
||||
// }
|
||||
//}
|
||||
|
||||
//ping порта
|
||||
err = port_checker.CheckPort_err(Settings.DB_HOST, Settings.DB_PORT)
|
||||
@@ -447,7 +448,8 @@ func GetConnection() *pgx.Conn {
|
||||
// GetConnection_WithApplicationName - возвращает соединение к нужной базе данных, с указанием имени приложения
|
||||
func GetConnection_WithApplicationName(ApplicationName string) *pgx.Conn {
|
||||
if Conn == nil {
|
||||
Connect_WithApplicationName_err(ApplicationName)
|
||||
err := Connect_WithApplicationName_err(ApplicationName)
|
||||
LogInfo_Connected(err)
|
||||
}
|
||||
|
||||
return Conn
|
||||
|
||||
Reference in New Issue
Block a user