1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-24 22:53:52 +02:00

сделал GetConnection().

This commit is contained in:
Nikitin Aleksandr
2025-05-05 15:46:42 +03:00
parent 88c245e164
commit b7a16179ef

View File

@@ -121,7 +121,7 @@ func Connect_WithApplicationName_err(ApplicationName string) error {
} }
if err == nil { if err == nil {
err = Conn.Ping(ctx) err = GetConnection().Ping(ctx)
} }
return err return err
@@ -149,7 +149,7 @@ func IsClosed() bool {
} }
ctx := contextmain.GetContext() ctx := contextmain.GetContext()
err := Conn.Ping(ctx) err := GetConnection().Ping(ctx)
if err != nil { if err != nil {
otvet = true otvet = true
} }
@@ -234,7 +234,7 @@ func CloseConnection_err() error {
mutexReconnect.Lock() mutexReconnect.Lock()
defer mutexReconnect.Unlock() defer mutexReconnect.Unlock()
err := Conn.Close(ctx) err := GetConnection().Close(ctx)
return err return err
} }
@@ -374,7 +374,7 @@ loop:
//ping в базе данных //ping в базе данных
mutexReconnect.RLock() //race mutexReconnect.RLock() //race
err = Conn.Ping(ctx) err = GetConnection().Ping(ctx)
mutexReconnect.RUnlock() mutexReconnect.RUnlock()
if err != nil { if err != nil {
switch err.Error() { switch err.Error() {
@@ -391,7 +391,7 @@ loop:
} else { } else {
//IsClosed //IsClosed
if Conn.IsClosed() == true { if GetConnection().IsClosed() == true {
NeedReconnect = true NeedReconnect = true
log.Error("postgres_pgx error: IsClosed() = true") log.Error("postgres_pgx error: IsClosed() = true")
} }
@@ -419,7 +419,7 @@ loop:
// GetConnection - возвращает соединение к нужной базе данных // GetConnection - возвращает соединение к нужной базе данных
func GetConnection() *pgx.Conn { func GetConnection() *pgx.Conn {
if Conn == nil || Conn.IsClosed() { if Conn == nil || GetConnection().IsClosed() {
err := Connect_err() err := Connect_err()
if err != nil { if err != nil {
log.Error("POSTGRES pgx Connect() to database host: ", Settings.DB_HOST, ", error: ", err) log.Error("POSTGRES pgx Connect() to database host: ", Settings.DB_HOST, ", error: ", err)