optimzie of postgres db code
This commit is contained in:
parent
2126aa7b06
commit
02e0c9c31a
|
|
@ -13,15 +13,11 @@ import (
|
||||||
var (
|
var (
|
||||||
postgresOnce sync.Once
|
postgresOnce sync.Once
|
||||||
_globalPostgresClient *gorm.DB
|
_globalPostgresClient *gorm.DB
|
||||||
_globalPostgresMu sync.RWMutex
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetPostgresDBClient returns the global PostgresDB client.It's safe for concurrent use.
|
// GetPostgresDBClient returns the global PostgresDB client.It's safe for concurrent use.
|
||||||
func GetPostgresDBClient() *gorm.DB {
|
func GetPostgresDBClient() *gorm.DB {
|
||||||
_globalPostgresMu.RLock()
|
return _globalPostgresClient
|
||||||
client := _globalPostgresClient
|
|
||||||
_globalPostgresMu.RUnlock()
|
|
||||||
return client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitPostgresDBInstance return instance of PostgresDB client
|
// InitPostgresDBInstance return instance of PostgresDB client
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue