@@ -62,8 +62,8 @@ type DBInfo struct {
62
62
InstanceStartTime string `json:"instance_start_time"`
63
63
}
64
64
65
- // DBConnectionDef contains parameters
66
- type DBConnectionDef struct {
65
+ // CouchDBConnectionDef contains parameters
66
+ type CouchDBConnectionDef struct {
67
67
URL string
68
68
Username string
69
69
Password string
@@ -78,7 +78,7 @@ type CouchDBReturn struct {
78
78
}
79
79
80
80
//CreateConnectionDefinition for a new client connection
81
- func CreateConnectionDefinition (host string , port int , databaseName , username , password string ) (* DBConnectionDef , error ) {
81
+ func CreateConnectionDefinition (host string , port int , databaseName , username , password string ) (* CouchDBConnectionDef , error ) {
82
82
83
83
logger .Debugf ("===COUCHDB=== Entering CreateConnectionDefinition()" )
84
84
@@ -94,6 +94,7 @@ func CreateConnectionDefinition(host string, port int, databaseName, username, p
94
94
//parse the constructed URL to verify no errors
95
95
finalURL , err := url .Parse (urlConcat )
96
96
if err != nil {
97
+ logger .Errorf ("===COUCHDB=== URL parse error: %s" , err .Error ())
97
98
return nil , err
98
99
}
99
100
@@ -102,11 +103,11 @@ func CreateConnectionDefinition(host string, port int, databaseName, username, p
102
103
logger .Debugf ("===COUCHDB=== Exiting CreateConnectionDefinition()" )
103
104
104
105
//return an object containing the connection information
105
- return & DBConnectionDef {finalURL .String (), username , password , databaseName }, nil
106
+ return & CouchDBConnectionDef {finalURL .String (), username , password , databaseName }, nil
106
107
}
107
108
108
109
//CreateDatabaseIfNotExist method provides function to create database
109
- func (dbclient * DBConnectionDef ) CreateDatabaseIfNotExist () (* DBOperationResponse , error ) {
110
+ func (dbclient * CouchDBConnectionDef ) CreateDatabaseIfNotExist () (* DBOperationResponse , error ) {
110
111
111
112
logger .Debugf ("===COUCHDB=== Entering CreateDatabaseIfNotExist()" )
112
113
@@ -154,7 +155,7 @@ func (dbclient *DBConnectionDef) CreateDatabaseIfNotExist() (*DBOperationRespons
154
155
}
155
156
156
157
//GetDatabaseInfo method provides function to retrieve database information
157
- func (dbclient * DBConnectionDef ) GetDatabaseInfo () (* DBInfo , * CouchDBReturn , error ) {
158
+ func (dbclient * CouchDBConnectionDef ) GetDatabaseInfo () (* DBInfo , * CouchDBReturn , error ) {
158
159
159
160
url := fmt .Sprintf ("%s/%s" , dbclient .URL , dbclient .Database )
160
161
@@ -167,12 +168,20 @@ func (dbclient *DBConnectionDef) GetDatabaseInfo() (*DBInfo, *CouchDBReturn, err
167
168
dbResponse := & DBInfo {}
168
169
json .NewDecoder (resp .Body ).Decode (& dbResponse )
169
170
171
+ // trace the database info response
172
+ if logger .IsEnabledFor (logging .DEBUG ) {
173
+ dbResponseJSON , err := json .Marshal (dbResponse )
174
+ if err == nil {
175
+ logger .Debugf ("===COUCHDB=== GetDatabaseInfo() dbResponseJSON: %s" , dbResponseJSON )
176
+ }
177
+ }
178
+
170
179
return dbResponse , couchDBReturn , nil
171
180
172
181
}
173
182
174
183
//DropDatabase provides method to drop an existing database
175
- func (dbclient * DBConnectionDef ) DropDatabase () (* DBOperationResponse , error ) {
184
+ func (dbclient * CouchDBConnectionDef ) DropDatabase () (* DBOperationResponse , error ) {
176
185
177
186
logger .Debugf ("===COUCHDB=== Entering DropDatabase()" )
178
187
@@ -206,7 +215,7 @@ func (dbclient *DBConnectionDef) DropDatabase() (*DBOperationResponse, error) {
206
215
}
207
216
208
217
//SaveDoc method provides a function to save a document, id and byte array
209
- func (dbclient * DBConnectionDef ) SaveDoc (id string , bytesDoc []byte ) (string , error ) {
218
+ func (dbclient * CouchDBConnectionDef ) SaveDoc (id string , bytesDoc []byte ) (string , error ) {
210
219
211
220
logger .Debugf ("===COUCHDB=== Entering SaveDoc()" )
212
221
@@ -246,7 +255,7 @@ func getRevisionHeader(resp *http.Response) (string, error) {
246
255
}
247
256
248
257
//ReadDoc method provides function to retrieve a document from the database by id
249
- func (dbclient * DBConnectionDef ) ReadDoc (id string ) ([]byte , string , error ) {
258
+ func (dbclient * CouchDBConnectionDef ) ReadDoc (id string ) ([]byte , string , error ) {
250
259
251
260
logger .Debugf ("===COUCHDB=== Entering ReadDoc() id=%s" , id )
252
261
@@ -277,7 +286,7 @@ func (dbclient *DBConnectionDef) ReadDoc(id string) ([]byte, string, error) {
277
286
}
278
287
279
288
//handleRequest method is a generic http request handler
280
- func (dbclient * DBConnectionDef ) handleRequest (method , url string , data io.Reader ) (* http.Response , * CouchDBReturn , error ) {
289
+ func (dbclient * CouchDBConnectionDef ) handleRequest (method , url string , data io.Reader ) (* http.Response , * CouchDBReturn , error ) {
281
290
282
291
logger .Debugf ("===COUCHDB=== Entering handleRequest() method=%s url=%s" , method , url )
283
292
0 commit comments