-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_versioned.go
69 lines (57 loc) · 2.36 KB
/
connection_versioned.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sofa
import (
"time"
)
// CouchDB1Connection is a connection specifically for a version 1 server.
type CouchDB1Connection struct {
*Connection
}
// CouchDB2Connection is a connection specifically for a version 2 server.
type CouchDB2Connection struct {
*Connection
}
// CouchDB3Connection is a connection specifically for a version 3 server.
type CouchDB3Connection struct {
*CouchDB2Connection
}
// NewConnection creates a new CouchDB1Connection which can be used to interact with a single CouchDB server.
// Any query parameters passed in the serverUrl are discarded before creating the connection.
func NewConnection(serverURL string, timeout time.Duration, auth Authenticator) (*CouchDB1Connection, error) {
con, err := newConnection(serverURL, timeout, auth)
if err != nil {
return nil, err
}
return &CouchDB1Connection{con}, nil
}
// NewConnection2 creates a new CouchDB2Connection which can be used to interact with a single CouchDB server.
// Any query parameters passed in the serverUrl are discarded before creating the connection.
func NewConnection2(serverURL string, timeout time.Duration, auth Authenticator) (*CouchDB2Connection, error) {
con, err := newConnection(serverURL, timeout, auth)
if err != nil {
return nil, err
}
return &CouchDB2Connection{con}, nil
}
// NewConnection3 creates a new CouchDB3Connection which can be used to interact with a single CouchDB server.
// Any query parameters passed in the serverUrl are discarded before creating the connection.
func NewConnection3(serverURL string, timeout time.Duration, auth Authenticator) (*CouchDB3Connection, error) {
con, err := NewConnection2(serverURL, timeout, auth)
if err != nil {
return nil, err
}
return &CouchDB3Connection{con}, nil
}
// ServerInfo gets the information about this CouchDB instance returned when accessing the root
// page
func (con *CouchDB1Connection) ServerInfo() (ServerDetails1, error) {
d := ServerDetails1{}
_, err := con.unmarshalRequest("GET", "/", NewURLOptions(), nil, &d)
return d, err
}
// ServerInfo gets the information about this CouchDB instance returned when accessing the root
// page
func (con *CouchDB2Connection) ServerInfo() (ServerDetails2, error) {
d := ServerDetails2{}
_, err := con.unmarshalRequest("GET", "/", NewURLOptions(), nil, &d)
return d, err
}