-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.go
51 lines (41 loc) · 1.09 KB
/
global.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package global
import (
"sync"
"github.com/songzhibin97/gkit/cache/local_cache"
"github.com/spark8899/ops-manager/server/utils/timer"
"golang.org/x/sync/singleflight"
"go.uber.org/zap"
"github.com/spark8899/ops-manager/server/config"
"github.com/go-redis/redis/v8"
"github.com/spf13/viper"
"gorm.io/gorm"
)
var (
OPM_DB *gorm.DB
OPM_DBList map[string]*gorm.DB
OPM_REDIS *redis.Client
OPM_CONFIG config.Server
OPM_VP *viper.Viper
// OPM_LOG *oplogging.Logger
OPM_LOG *zap.Logger
OPM_Timer timer.Timer = timer.NewTimerTask()
OPM_Concurrency_Control = &singleflight.Group{}
BlackCache local_cache.Cache
lock sync.RWMutex
)
// GetGlobalDBByDBName get by name db list' db
func GetGlobalDBByDBName(dbname string) *gorm.DB {
lock.RLock()
defer lock.RUnlock()
return OPM_DBList[dbname]
}
// MustGetGlobalDBByDBName get by name db, panic if not present
func MustGetGlobalDBByDBName(dbname string) *gorm.DB {
lock.RLock()
defer lock.RUnlock()
db, ok := OPM_DBList[dbname]
if !ok || db == nil {
panic("db no init")
}
return db
}