mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-04 03:12:19 +08:00
20 lines
455 B
Go
20 lines
455 B
Go
package tx
|
|
|
|
import (
|
|
"context"
|
|
"github.com/OpenIMSDK/tools/tx"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
func NewAuto(ctx context.Context, cli *mongo.Client) (tx.CtxTx, error) {
|
|
var res map[string]any
|
|
if err := cli.Database("admin").RunCommand(ctx, bson.M{"isMaster": 1}).Decode(&res); err != nil {
|
|
return nil, err
|
|
}
|
|
if _, ok := res["setName"]; ok {
|
|
return NewMongoTx(cli), nil
|
|
}
|
|
return NewInvalidTx(), nil
|
|
}
|