JM-WechatMini/global/global.go

56 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-11-02 04:34:46 +08:00
package global
import (
2023-11-10 09:30:29 +08:00
"miniapp/utils/flashtext"
2023-11-02 04:34:46 +08:00
"sync"
"github.com/songzhibin97/gkit/cache/local_cache"
"miniapp/utils/timer"
"golang.org/x/sync/singleflight"
"go.uber.org/zap"
"miniapp/config"
"github.com/redis/go-redis/v9"
"github.com/spf13/viper"
"gorm.io/gorm"
)
var (
GVA_DB *gorm.DB
GVA_DBList map[string]*gorm.DB
GVA_REDIS *redis.Client
GVA_CONFIG config.Server
GVA_VP *viper.Viper
// GVA_LOG *oplogging.Logger
GVA_LOG *zap.Logger
GVA_Timer timer.Timer = timer.NewTimerTask()
GVA_Concurrency_Control = &singleflight.Group{}
BlackCache local_cache.Cache
lock sync.RWMutex
2023-11-10 09:30:29 +08:00
// GVA_Kp 关键词处理器
GVA_Kp *flashtext.KeywordProcessor
2023-11-02 04:34:46 +08:00
)
// GetGlobalDBByDBName 通过名称获取db list中的db
func GetGlobalDBByDBName(dbname string) *gorm.DB {
lock.RLock()
defer lock.RUnlock()
return GVA_DBList[dbname]
}
// MustGetGlobalDBByDBName 通过名称获取db 如果不存在则panic
func MustGetGlobalDBByDBName(dbname string) *gorm.DB {
lock.RLock()
defer lock.RUnlock()
db, ok := GVA_DBList[dbname]
if !ok || db == nil {
panic("db no init")
}
return db
}