github.com/go-kivik/kivik/v4@v4.3.2/couchdb/couchdb.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 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 // couch represents the parent driver instance. 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 // schedulerDetected will be set once the scheduler has been detected. 38 // It should only be accessed through the schedulerSupported() method. 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 }