mongo dbname도 url에서 받음
This commit is contained in:
@ -2,14 +2,12 @@ package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
)
|
||||
@ -25,18 +23,8 @@ type sessionMongo struct {
|
||||
Ts primitive.DateTime `bson:"_ts"`
|
||||
}
|
||||
|
||||
var errNoDatabaseNameInMongoUri = errors.New("mongo uri has no database name")
|
||||
|
||||
func newProviderWithMongo(ctx context.Context, mongoUrl string, ttl time.Duration) (Provider, error) {
|
||||
connstr, err := connstring.ParseAndValidate(mongoUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(connstr.Database) == 0 {
|
||||
return nil, errNoDatabaseNameInMongoUri
|
||||
}
|
||||
|
||||
mc, err := gocommon.NewMongoClient(ctx, mongoUrl, connstr.Database)
|
||||
mc, err := gocommon.NewMongoClient(ctx, mongoUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -105,16 +93,7 @@ type sessionPipelineDocument struct {
|
||||
}
|
||||
|
||||
func newConsumerWithMongo(ctx context.Context, mongoUrl string, ttl time.Duration) (Consumer, error) {
|
||||
connstr, err := connstring.ParseAndValidate(mongoUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(connstr.Database) == 0 {
|
||||
return nil, errNoDatabaseNameInMongoUri
|
||||
}
|
||||
|
||||
mc, err := gocommon.NewMongoClient(ctx, mongoUrl, connstr.Database)
|
||||
mc, err := gocommon.NewMongoClient(ctx, mongoUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user