Skip to content

Commit

Permalink
Rename composeURI func to composeMongoURI
Browse files Browse the repository at this point in the history
To reflect that it's used exclusively for MongoDB (for now at least).

Also added a descriptive comment to the function.
  • Loading branch information
ionutboangiu authored and danbogos committed Dec 7, 2023
1 parent a057b34 commit 7886a35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion engine/storage_mongo_datadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func NewMongoStorage(host, port, db, user, pass, mrshlerStr string, storageType
storageType: storageType,
counter: utils.NewCounter(time.Now().UnixNano(), 0),
}
uri := composeURI("mongodb", host, port, db, user, pass)
uri := composeMongoURI("mongodb", host, port, db, user, pass)
reg := bson.NewRegistry()
decimalType := reflect.TypeOf(utils.Decimal{})
reg.RegisterTypeEncoder(decimalType, bsoncodec.ValueEncoderFunc(decimalEncoder))
Expand Down
2 changes: 1 addition & 1 deletion engine/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ func TestComposeURI(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
url := composeURI(tt.scheme, tt.host, tt.port, tt.db, tt.user, tt.pass)
url := composeMongoURI(tt.scheme, tt.host, tt.port, tt.db, tt.user, tt.pass)
if url != tt.expected {
t.Errorf("expected %v,\nreceived %v", tt.expected, url)
}
Expand Down
12 changes: 11 additions & 1 deletion engine/storage_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ func NewStorDBConn(dbType, host, port, name, user, pass, marshaler string,
return
}

func composeURI(scheme, host, port, db, user, pass string) string {
// composeMongoURI constructs a MongoDB URI from the given parameters:
// - scheme: only "mongodb" for now.
// - host: MongoDB server host (e.g., "localhost").
// - port: MongoDB server port, excluded if "0".
// - db: Database name, may include additional parameters (e.g., "db?retryWrites=true").
// - user: Username for auth, omitted if empty.
// - pass: Password for auth, only if username is set.
//
// TODO: Decide whether to replace the 'scheme' string parameter with a boolean once support
// for "mongodb+srv" is added.
func composeMongoURI(scheme, host, port, db, user, pass string) string {
uri := scheme + "://"
if user != "" && pass != "" {
uri += user + ":" + pass + "@"
Expand Down

0 comments on commit 7886a35

Please sign in to comment.