@@ -291,7 +291,7 @@ func (dbclient *CouchDatabase) CreateDatabaseIfNotExist() error {
291
291
logger .Errorf ("URL parse error: %s" , err )
292
292
return errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
293
293
}
294
- connectURL . Path = dbclient .DBName
294
+ connectURL = constructCouchDBUrl ( connectURL , dbclient .DBName , "" )
295
295
296
296
//get the number of retries
297
297
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -367,7 +367,7 @@ func (dbclient *CouchDatabase) GetDatabaseInfo() (*DBInfo, *DBReturn, error) {
367
367
logger .Errorf ("URL parse error: %s" , err )
368
368
return nil , nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
369
369
}
370
- connectURL . Path = dbclient .DBName
370
+ connectURL = constructCouchDBUrl ( connectURL , dbclient .DBName , "" )
371
371
372
372
//get the number of retries
373
373
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -456,7 +456,7 @@ func (dbclient *CouchDatabase) DropDatabase() (*DBOperationResponse, error) {
456
456
logger .Errorf ("URL parse error: %s" , err )
457
457
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
458
458
}
459
- connectURL . Path = dbclient .DBName
459
+ connectURL = constructCouchDBUrl ( connectURL , dbclient .DBName , "" )
460
460
461
461
//get the number of retries
462
462
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -499,7 +499,7 @@ func (dbclient *CouchDatabase) EnsureFullCommit() (*DBOperationResponse, error)
499
499
logger .Errorf ("URL parse error: %s" , err )
500
500
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
501
501
}
502
- connectURL . Path = dbclient .DBName + "/ _ensure_full_commit"
502
+ connectURL = constructCouchDBUrl ( connectURL , dbclient .DBName , " _ensure_full_commit")
503
503
504
504
//get the number of retries
505
505
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -562,9 +562,7 @@ func (dbclient *CouchDatabase) SaveDoc(id string, rev string, couchDoc *CouchDoc
562
562
return "" , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
563
563
}
564
564
565
- saveURL .Path = dbclient .DBName
566
- // id can contain a '/', so encode separately
567
- saveURL = & url.URL {Opaque : saveURL .String () + "/" + encodePathElement (id )}
565
+ saveURL = constructCouchDBUrl (saveURL , dbclient .DBName , id )
568
566
569
567
logger .Debugf (" rev=%s" , rev )
570
568
@@ -616,7 +614,7 @@ func (dbclient *CouchDatabase) SaveDoc(id string, rev string, couchDoc *CouchDoc
616
614
617
615
//handle the request for saving document with a retry if there is a revision conflict
618
616
resp , _ , err := dbclient .handleRequestWithRevisionRetry (id , http .MethodPut ,
619
- * saveURL , data , rev , defaultBoundary , maxRetries , keepConnectionOpen )
617
+ saveURL . String () , data , rev , defaultBoundary , maxRetries , keepConnectionOpen )
620
618
621
619
if err != nil {
622
620
return "" , err
@@ -762,9 +760,8 @@ func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error) {
762
760
logger .Errorf ("URL parse error: %s" , err )
763
761
return nil , "" , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
764
762
}
765
- readURL .Path = dbclient .DBName
766
- // id can contain a '/', so encode separately
767
- readURL = & url.URL {Opaque : readURL .String () + "/" + encodePathElement (id )}
763
+
764
+ readURL = constructCouchDBUrl (readURL , dbclient .DBName , id )
768
765
769
766
query := readURL .Query ()
770
767
query .Add ("attachments" , "true" )
@@ -895,7 +892,7 @@ func (dbclient *CouchDatabase) ReadDocRange(startKey, endKey string, limit, skip
895
892
logger .Errorf ("URL parse error: %s" , err )
896
893
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
897
894
}
898
- rangeURL . Path = dbclient .DBName + "/ _all_docs"
895
+ rangeURL = constructCouchDBUrl ( rangeURL , dbclient .DBName , " _all_docs")
899
896
900
897
queryParms := rangeURL .Query ()
901
898
queryParms .Set ("limit" , strconv .Itoa (limit ))
@@ -1001,17 +998,14 @@ func (dbclient *CouchDatabase) DeleteDoc(id, rev string) error {
1001
998
logger .Errorf ("URL parse error: %s" , err )
1002
999
return errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1003
1000
}
1004
-
1005
- deleteURL .Path = dbclient .DBName
1006
- // id can contain a '/', so encode separately
1007
- deleteURL = & url.URL {Opaque : deleteURL .String () + "/" + encodePathElement (id )}
1001
+ deleteURL = constructCouchDBUrl (deleteURL , dbclient .DBName , id )
1008
1002
1009
1003
//get the number of retries
1010
1004
maxRetries := dbclient .CouchInstance .conf .MaxRetries
1011
1005
1012
1006
//handle the request for saving document with a retry if there is a revision conflict
1013
1007
resp , couchDBReturn , err := dbclient .handleRequestWithRevisionRetry (id , http .MethodDelete ,
1014
- * deleteURL , nil , "" , "" , maxRetries , true )
1008
+ deleteURL . String () , nil , "" , "" , maxRetries , true )
1015
1009
1016
1010
if err != nil {
1017
1011
if couchDBReturn != nil && couchDBReturn .StatusCode == 404 {
@@ -1042,8 +1036,7 @@ func (dbclient *CouchDatabase) QueryDocuments(query string) (*[]QueryResult, err
1042
1036
logger .Errorf ("URL parse error: %s" , err )
1043
1037
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1044
1038
}
1045
-
1046
- queryURL .Path = dbclient .DBName + "/_find"
1039
+ queryURL = constructCouchDBUrl (queryURL , dbclient .DBName , "_find" )
1047
1040
1048
1041
//get the number of retries
1049
1042
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -1132,8 +1125,7 @@ func (dbclient *CouchDatabase) ListIndex() ([]*IndexResult, error) {
1132
1125
logger .Errorf ("URL parse error: %s" , err )
1133
1126
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1134
1127
}
1135
-
1136
- indexURL .Path = dbclient .DBName + "/_index/"
1128
+ indexURL = constructCouchDBUrl (indexURL , dbclient .DBName , "_index" )
1137
1129
1138
1130
//get the number of retries
1139
1131
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -1196,8 +1188,7 @@ func (dbclient *CouchDatabase) CreateIndex(indexdefinition string) (*CreateIndex
1196
1188
logger .Errorf ("URL parse error: %s" , err )
1197
1189
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1198
1190
}
1199
-
1200
- indexURL .Path = dbclient .DBName + "/_index"
1191
+ indexURL = constructCouchDBUrl (indexURL , dbclient .DBName , "_index" )
1201
1192
1202
1193
//get the number of retries
1203
1194
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -1251,8 +1242,7 @@ func (dbclient *CouchDatabase) DeleteIndex(designdoc, indexname string) error {
1251
1242
logger .Errorf ("URL parse error: %s" , err )
1252
1243
return errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1253
1244
}
1254
-
1255
- indexURL .Path = dbclient .DBName + "/_index/" + designdoc + "/json/" + indexname
1245
+ indexURL = constructCouchDBUrl (indexURL , dbclient .DBName , "_index" , designdoc , "json" , indexname )
1256
1246
1257
1247
//get the number of retries
1258
1248
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -1279,7 +1269,7 @@ func (dbclient *CouchDatabase) WarmIndex(designdoc, indexname string) error {
1279
1269
}
1280
1270
1281
1271
//URL to execute the view function associated with the index
1282
- indexURL . Path = dbclient .DBName + "/ _design/" + designdoc + "/ _view/" + indexname
1272
+ indexURL = constructCouchDBUrl ( indexURL , dbclient .DBName , " _design" , designdoc , " _view" , indexname )
1283
1273
1284
1274
queryParms := indexURL .Query ()
1285
1275
//Query parameter that allows the execution of the URL to return immediately
@@ -1347,8 +1337,7 @@ func (dbclient *CouchDatabase) GetDatabaseSecurity() (*DatabaseSecurity, error)
1347
1337
logger .Errorf ("URL parse error: %s" , err )
1348
1338
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1349
1339
}
1350
-
1351
- securityURL .Path = dbclient .DBName + "/_security"
1340
+ securityURL = constructCouchDBUrl (securityURL , dbclient .DBName , "_security" )
1352
1341
1353
1342
//get the number of retries
1354
1343
maxRetries := dbclient .CouchInstance .conf .MaxRetries
@@ -1390,8 +1379,7 @@ func (dbclient *CouchDatabase) ApplyDatabaseSecurity(databaseSecurity *DatabaseS
1390
1379
logger .Errorf ("URL parse error: %s" , err )
1391
1380
return errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1392
1381
}
1393
-
1394
- securityURL .Path = dbclient .DBName + "/_security"
1382
+ securityURL = constructCouchDBUrl (securityURL , dbclient .DBName , "_security" )
1395
1383
1396
1384
//Ensure all of the arrays are initialized to empty arrays instead of nil
1397
1385
if databaseSecurity .Admins .Names == nil {
@@ -1441,7 +1429,7 @@ func (dbclient *CouchDatabase) BatchRetrieveDocumentMetadata(keys []string) ([]*
1441
1429
logger .Errorf ("URL parse error: %s" , err )
1442
1430
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1443
1431
}
1444
- batchRetrieveURL . Path = dbclient .DBName + "/ _all_docs"
1432
+ batchRetrieveURL = constructCouchDBUrl ( batchRetrieveURL , dbclient .DBName , " _all_docs")
1445
1433
1446
1434
queryParms := batchRetrieveURL .Query ()
1447
1435
@@ -1521,7 +1509,7 @@ func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*B
1521
1509
logger .Errorf ("URL parse error: %s" , err )
1522
1510
return nil , errors .Wrapf (err , "error parsing CouchDB URL: %s" , dbclient .CouchInstance .conf .URL )
1523
1511
}
1524
- batchUpdateURL . Path = dbclient .DBName + "/ _bulk_docs"
1512
+ batchUpdateURL = constructCouchDBUrl ( batchUpdateURL , dbclient .DBName , " _bulk_docs")
1525
1513
1526
1514
documentMap := make (map [string ]interface {})
1527
1515
@@ -1606,7 +1594,7 @@ func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*B
1606
1594
//a retry for document revision conflict errors,
1607
1595
//which may be detected during saves or deletes that timed out from client http perspective,
1608
1596
//but which eventually succeeded in couchdb
1609
- func (dbclient * CouchDatabase ) handleRequestWithRevisionRetry (id , method string , connectURL url. URL , data []byte , rev string ,
1597
+ func (dbclient * CouchDatabase ) handleRequestWithRevisionRetry (id , method , connectURL string , data []byte , rev string ,
1610
1598
multipartBoundary string , maxRetries int , keepConnectionOpen bool ) (* http.Response , * DBReturn , error ) {
1611
1599
1612
1600
//Initialize a flag for the revision conflict
@@ -1627,7 +1615,7 @@ func (dbclient *CouchDatabase) handleRequestWithRevisionRetry(id, method string,
1627
1615
}
1628
1616
1629
1617
//handle the request for saving/deleting the couchdb data
1630
- resp , couchDBReturn , errResp = dbclient .CouchInstance .handleRequest (method , connectURL . String () ,
1618
+ resp , couchDBReturn , errResp = dbclient .CouchInstance .handleRequest (method , connectURL ,
1631
1619
data , rev , multipartBoundary , maxRetries , keepConnectionOpen )
1632
1620
1633
1621
//If there was a 409 conflict error during the save/delete, log it and retry it.
0 commit comments