1 Star 0 Fork 0

danlansky/go-library

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mongo.go 789 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhangminghua 提交于 2024-08-20 14:32 . feat:基础工具包
package initialization
import (
"gitee.com/danlansky/go-library/logs"
"sync"
db "gitee.com/danlansky/go-library/base/mongo"
"gitee.com/danlansky/go-library/repository/mongo"
"github.com/spf13/viper"
"go.uber.org/zap"
)
const defaultMongoDBConfigTag = "mongo"
var mongoOnce sync.Once
func initMongo() {
mongoOnce.Do(func() {
mongoConfigMap := make(map[string]mongo.Setting)
_ = viper.UnmarshalKey(defaultMongoDBConfigTag, &mongoConfigMap)
for _, mongoConfig := range mongoConfigMap {
conn, err := mongo.InitMongo(mongoConfig)
if err != nil {
logs.ErrorLog("Mongo init err", zap.String("mongo", err.Error()))
panic(err)
}
db.ConnectMap[mongoConfig.Name] = conn
logs.AccessLog("MongoDB init success!", zap.String("mongo", mongoConfig.Name))
}
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/danlansky/go-library.git
git@gitee.com:danlansky/go-library.git
danlansky
go-library
go-library
v1.0.0

搜索帮助