...
1
2
3
4
5
6
7
8
9
10
11
12
13 package couchdb
14
15 import (
16 "net/http"
17 "net/url"
18 "sync"
19
20 kivik "github.com/go-kivik/kivik/v4"
21 "github.com/go-kivik/kivik/v4/couchdb/chttp"
22 "github.com/go-kivik/kivik/v4/driver"
23 )
24
25
26 type couch struct{}
27
28 var _ driver.Driver = &couch{}
29
30 func init() {
31 kivik.Register("couch", &couch{})
32 }
33
34 type client struct {
35 *chttp.Client
36
37
38
39 schedulerDetected *bool
40 sdMU sync.Mutex
41 }
42
43 var (
44 _ driver.Client = &client{}
45 _ driver.DBUpdater = &client{}
46 )
47
48 func (d *couch) NewClient(dsn string, options driver.Options) (driver.Client, error) {
49 httpClient := &http.Client{}
50 options.Apply(httpClient)
51 chttpClient, err := chttp.New(httpClient, dsn, options)
52 if err != nil {
53 return nil, err
54 }
55 return &client{
56 Client: chttpClient,
57 }, nil
58 }
59
60 func (c *client) DB(dbName string, _ driver.Options) (driver.DB, error) {
61 if dbName == "" {
62 return nil, missingArg("dbName")
63 }
64 return &db{
65 client: c,
66 dbName: url.PathEscape(dbName),
67 }, nil
68 }
69
View as plain text