mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
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:
committed by
Dan Christian Bogos
parent
a057b34505
commit
7886a35d63
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 + "@"
|
||||
|
||||
Reference in New Issue
Block a user