Rename composeURI func to composeMongoURI

To reflect that it's used exclusively for MongoDB (for now at least).

Also added a descriptive comment to the function.
This commit is contained in:
ionutboangiu
2023-12-06 02:46:40 -05:00
committed by Dan Christian Bogos
parent 8909786a4b
commit f0852b645b
3 changed files with 13 additions and 3 deletions

View File

@@ -156,7 +156,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))

View File

@@ -281,7 +281,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)
}

View File

@@ -80,7 +80,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 + "@"