We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
将mongodb、redis数据库连接整合至globeDatabaseConfig
The text was updated successfully, but these errors were encountered:
或者数据库都放在repo目录里面加全局变量?
var RDB redis.Conn func init() { // gorm initalization here... initRedis() } // 初始化redis配置信息 func initRedis() { log.NewLog("info").Info("初始化Redis...") addr := config.AppConfig.Redis.Host + config.AppConfig.Redis.Port RD, err := redis.Dial("tcp", addr, redis.DialPassword(config.AppConfig.Redis.Password)) if err != nil { log.NewLog(constants.ERROR).Error("Redis连接失败...", err) panic(err) } RDB = RD rand.Seed(time.Now().UnixNano()) log.NewLog(constants.INFO).Info("初始化Redis结束...", RDB) }
使用直接repo.RDB就能自动init()启动所有数据库连接,比在globalDatabaseConfig里面再手动调用Get会好一些
repo.RDB
init()
Sorry, something went wrong.
Wenrh2004
No branches or pull requests
将mongodb、redis数据库连接整合至globeDatabaseConfig
The text was updated successfully, but these errors were encountered: