refactor: db/redis/mongo连接代码包独立

This commit is contained in:
meilin.huang
2023-10-27 17:41:45 +08:00
parent a1303b52eb
commit 12f63ef3dd
45 changed files with 1112 additions and 950 deletions

View File

@@ -0,0 +1,24 @@
package mgm
import (
"context"
"mayfly-go/pkg/logx"
"go.mongodb.org/mongo-driver/mongo"
)
type MongoConn struct {
Id string
Info *MongoInfo
Cli *mongo.Client
}
func (mc *MongoConn) Close() {
if mc.Cli != nil {
if err := mc.Cli.Disconnect(context.Background()); err != nil {
logx.Errorf("关闭mongo实例[%s]连接失败: %s", mc.Id, err)
}
mc.Cli = nil
}
}