Skip to content

Commit

Permalink
fix the code style isseus
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Nov 18, 2023
1 parent 45f8b9e commit 94013b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions .remarkrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
listItemIndent=one
40 changes: 19 additions & 21 deletions extensions/store-mongodb/pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"fmt"

"github.com/linuxsuren/api-testing/pkg/testing/remote"
"github.com/linuxsuren/api-testing/pkg/util"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
Expand All @@ -38,30 +39,27 @@ func (s *dbserver) getClient(ctx context.Context) (collection *mongo.Collection,
store := remote.GetStoreFromContext(ctx)
if store == nil {
err = errors.New("no connect to mongodb")
} else {
databaseName := "testing"
collectionName := "atest"
return
}

if store.Properties != nil {
if v, ok := store.Properties["database"]; ok && v != "" {
databaseName = v
}
if v, ok := store.Properties["collection"]; ok && v != "" {
collectionName = v
}
}
if store.Properties == nil {
store.Properties = map[string]string{}
}

databaseName := util.EmptyThenDefault(store.Properties["database"], "testing")
collectionName := util.EmptyThenDefault(store.Properties["collection"], "atest")

address := fmt.Sprintf("mongodb://%s:%s@%s", store.Username, store.Password, store.URL)
var client *mongo.Client
client, err = mongo.Connect(ctx, options.Client().ApplyURI(address))
if err != nil {
return
}

address := fmt.Sprintf("mongodb://%s:%s@%s", store.Username, store.Password, store.URL)
var client *mongo.Client
client, err = mongo.Connect(ctx, options.Client().ApplyURI(address))
// TODO need a way to maintain the connection of it
if err == nil {
collection = client.Database(databaseName).Collection(collectionName)
if collection == nil {
if err = client.Database(databaseName).CreateCollection(ctx, collectionName); err == nil {
collection = client.Database(databaseName).Collection(collectionName)
if collection == nil {
if err = client.Database(databaseName).CreateCollection(ctx, collectionName); err == nil {
collection = client.Database(databaseName).Collection(collectionName)
}
}
}
}
return
Expand Down

0 comments on commit 94013b0

Please sign in to comment.