centrelized collection creation logic
This commit is contained in:
@@ -196,21 +196,12 @@ func (self *ServersDbHandler) GetInviteToken(ctx context.Context, token string)
|
||||
}
|
||||
|
||||
func NewInviteTokenDbHandler(config models.MongoDBConfig) (*InviteTokenDbHandler, error) {
|
||||
clientOptions := options.Client().ApplyURI(config.Url).SetAuth(options.Credential{
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithTimeoutCause(context.Background(), 30*time.Second, fmt.Errorf("Timeout"))
|
||||
defer cancel()
|
||||
|
||||
client, err := mongo.Connect(ctx, clientOptions)
|
||||
|
||||
collection, err := getMongoCollection(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &InviteTokenDbHandler{
|
||||
collection: client.Database(config.Database).Collection(config.Collection),
|
||||
collection: collection,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user