Documentation ¶
Index ¶
- Constants
- Variables
- func Endpoint(base url.URL, pathStr string, params url.Values) (string, error)
- type AllDBsQueryBuilder
- type AllDocsQueryBuilder
- type AllRow
- type AllRowValue
- type BulkDocsRequest
- type BulkDocsResponse
- type BulkJob
- type BulkJobI
- type Change
- type ChangeEvent
- type ChangeRow
- type ChangeRowChanges
- type ChangesQueryBuilder
- type CouchClient
- func (c *CouchClient) AllDBs(args *allDBsQuery) (*[]string, error)
- func (c *CouchClient) Delete(databaseName string) error
- func (c *CouchClient) Execute(job *Job)
- func (c *CouchClient) Exists(databaseName string) (bool, error)
- func (c *CouchClient) Get(databaseName string) (*Database, error)
- func (c *CouchClient) GetOrCreate(databaseName string) (*Database, error)
- func (c *CouchClient) LogIn() error
- func (c *CouchClient) LogOut()
- func (c *CouchClient) Ping() (err error)
- func (c *CouchClient) Stop()
- type CouchError
- type CredentialsExpiredResponse
- type Database
- func (d *Database) All(args *allDocsQuery) (<-chan *AllRow, error)
- func (d *Database) Bulk(batchSize int, batchMaxBytes int, flushSecs int) *Uploader
- func (d *Database) Changes(args *changesQuery) (<-chan *Change, error)
- func (d *Database) Delete(documentID, rev string) error
- func (d *Database) Get(documentID string, args *getQuery, target interface{}) error
- func (d *Database) Info() (*Info, error)
- func (d *Database) Set(document interface{}) (*DocumentMeta, error)
- type DocumentMeta
- type Follower
- type GetQueryBuilder
- type Info
- type Job
- type QueryBuilder
- type Uploader
- func (u *Uploader) AsyncFlush()
- func (u *Uploader) BulkUploadSimple(docs []interface{}) ([]BulkDocsResponse, error)
- func (u *Uploader) FireAndForget(doc interface{})
- func (u *Uploader) Flush()
- func (u *Uploader) Stop()
- func (u *Uploader) Upload(doc interface{}) *BulkJob
- func (u *Uploader) UploadNow(doc interface{}) *BulkJob
Constants ¶
const ( // ChangesInsert is a new document, with _rev starting with "1-" ChangesInsert = iota // ChangesUpdate is a new revison of an existing document ChangesUpdate // ChangesDelete is a document deletion ChangesDelete // ChangesHeartbeat is an empty line sent to keep the connection open ChangesHeartbeat // ChangesTerminated means far end closed the connection ChangesTerminated ChangesError )
Constants defining the possible event types in a changes feed
const (
VERSION = "0.1.0"
)
Variables ¶
var LogFunc = log.Printf
LogFunc is a function that logs the provided message with optional fmt.Sprintf-style arguments. By default, logs to the default log.Logger.
Functions ¶
Types ¶
type AllDBsQueryBuilder ¶
type AllDBsQueryBuilder interface { EndKey(string) AllDBsQueryBuilder InclusiveEnd() AllDBsQueryBuilder Limit(int) AllDBsQueryBuilder Skip(int) AllDBsQueryBuilder StartKey(string) AllDBsQueryBuilder Build() *allDBsQuery }
AllDBsQueryBuilder defines the available parameter-setting functions.
type AllDocsQueryBuilder ¶
type AllDocsQueryBuilder interface { Conflicts() AllDocsQueryBuilder DeletedConflicts() AllDocsQueryBuilder Descending() AllDocsQueryBuilder EndKey(string) AllDocsQueryBuilder IncludeDocs() AllDocsQueryBuilder InclusiveEnd() AllDocsQueryBuilder Key(string) AllDocsQueryBuilder Keys([]string) AllDocsQueryBuilder Limit(int) AllDocsQueryBuilder Meta() AllDocsQueryBuilder R(int) AllDocsQueryBuilder RevsInfo() AllDocsQueryBuilder Skip(int) AllDocsQueryBuilder StartKey(string) AllDocsQueryBuilder Build() *allDocsQuery }
AllDocsQueryBuilder defines the available parameter-setting functions.
func NewAllDocsQuery ¶
func NewAllDocsQuery() AllDocsQueryBuilder
NewAllDocsQuery is the entry point.
type AllRow ¶
type AllRow struct { ID string `json:"id"` Value AllRowValue `json:"value"` Doc interface{} `json:"doc"` }
AllRow represents a row in the json array returned by all_docs
type AllRowValue ¶
type AllRowValue struct {
Rev string `json:"rev"`
}
AllRowValue represents a part returned by _all_docs
type BulkDocsRequest ¶
type BulkDocsRequest struct { Docs []interface{} `json:"docs"` NewEdits bool `json:"new_edits"` }
BulkDocsRequest is the JSON body of a request to the _bulk_docs endpoint
type BulkDocsResponse ¶
type BulkDocsResponse struct { Error string `json:"error,omitempty"` ID string `json:"id"` Reason string `json:"reason,omitempty"` Rev string `json:"rev,omitempty"` }
BulkDocsResponse is the JSON body of the response from the _bulk_docs endpoint
type BulkJob ¶
type BulkJob struct { Error error Response *BulkDocsResponse // contains filtered or unexported fields }
BulkJob represents the state of a single document to be uploaded as part of a batch
type BulkJobI ¶
type BulkJobI interface { Wait() // contains filtered or unexported methods }
BulkJobI ...
type Change ¶
type Change struct { ID string Rev string Seq string Deleted bool Doc map[string]interface{} // Only present if Changes() called with include_docs=true }
Change represents a part returned by _changes
type ChangeEvent ¶
type ChangeEvent struct { EventType int Meta *DocumentMeta Seq string Doc map[string]interface{} Err error }
ChangeEvent is the message structure delivered by the Read function
type ChangeRow ¶
type ChangeRow struct { ID string `json:"id"` Seq string `json:"seq"` // If using CouchDB1.6, this is a number Changes []ChangeRowChanges `json:"changes"` Deleted bool `json:"deleted"` Doc map[string]interface{} `json:"doc"` }
ChangeRow represents a part returned by _changes
func (*ChangeRow) UnmarshalJSON ¶
UnmarshalJSON is here for coping with CouchDB1.6's sequence IDs being numbers, not strings as in Cloudant and CouchDB2.X.
type ChangeRowChanges ¶
type ChangeRowChanges struct {
Rev string `json:"rev"`
}
ChangeRowChanges represents a part returned by _changes
type ChangesQueryBuilder ¶
type ChangesQueryBuilder interface { Conflicts() ChangesQueryBuilder Descending() ChangesQueryBuilder DocIDs([]string) ChangesQueryBuilder Feed(string) ChangesQueryBuilder Filter(string) ChangesQueryBuilder Heartbeat(int) ChangesQueryBuilder IncludeDocs() ChangesQueryBuilder Limit(int) ChangesQueryBuilder SeqInterval(int) ChangesQueryBuilder Since(string) ChangesQueryBuilder Style(string) ChangesQueryBuilder Timeout(int) ChangesQueryBuilder Build() *changesQuery }
ChangesQueryBuilder defines the available parameter-setting functions.
func NewChangesQuery ¶
func NewChangesQuery() ChangesQueryBuilder
NewChangesQuery is the entry point.
type CouchClient ¶
type CouchClient struct {
// contains filtered or unexported fields
}
CouchClient is the representation of a client connection
func CreateClient ¶
func CreateClient(username, password, rootStrURL string, concurrency int) (*CouchClient, error)
CreateClient returns a new client (with max. retry 3 using a random 5-30 secs delay).
func CreateClientWithRetry ¶
func CreateClientWithRetry(username, password, rootStrURL string, concurrency, retryCountMax, retryDelayMin, retryDelayMax int) (*CouchClient, error)
CreateClientWithRetry returns a new client with configurable retry parameters
func (*CouchClient) AllDBs ¶
func (c *CouchClient) AllDBs(args *allDBsQuery) (*[]string, error)
AllDBs returns a list of all DBs
func (*CouchClient) Delete ¶
func (c *CouchClient) Delete(databaseName string) error
Delete deletes a specified database.
func (*CouchClient) Execute ¶
func (c *CouchClient) Execute(job *Job)
Execute submits a job for execution. The client must call `job.Wait()` before attempting access the response attribute. Always call `job.Close()` to ensure the underlying connection is terminated.
func (*CouchClient) Exists ¶
func (c *CouchClient) Exists(databaseName string) (bool, error)
Exists checks the existence of a specified database. Returns true if the database exists, else false.
func (*CouchClient) Get ¶
func (c *CouchClient) Get(databaseName string) (*Database, error)
Get returns a database. It is assumed to exist.
func (*CouchClient) GetOrCreate ¶
func (c *CouchClient) GetOrCreate(databaseName string) (*Database, error)
GetOrCreate returns a database. If the database doesn't exist on the server then it will be created.
func (*CouchClient) Ping ¶
func (c *CouchClient) Ping() (err error)
Ping can be used to check whether a server is alive. It sends an HTTP HEAD request to the server's URL.
func (*CouchClient) Stop ¶
func (c *CouchClient) Stop()
Stop kills all running workers. Once called the client is no longer able to execute new jobs.
type CouchError ¶
CouchError is a server error response
func (*CouchError) Error ¶
func (e *CouchError) Error() string
Error() implements the error interface
type CredentialsExpiredResponse ¶
type CredentialsExpiredResponse struct {
Error string `json:"error"`
}
type Database ¶
Database holds a reference to an authenticated client connection and the name of a remote database
func (*Database) Changes ¶
Changes returns a channel in which Change types can be received. See: https://console.bluemix.net/docs/services/Cloudant/api/database.html#get-changes
func (*Database) Get ¶
Get a document from the database. See: https://console.bluemix.net/docs/services/Cloudant/api/document.html#read
func (*Database) Info ¶
Info returns database information. See https://console.bluemix.net/docs/services/Cloudant/api/database.html#getting-database-details
func (*Database) Set ¶
func (d *Database) Set(document interface{}) (*DocumentMeta, error)
Set a document. The specified type may have a json attributes '_id' and '_rev'. If no '_id' is given the database will generate one for you.
type DocumentMeta ¶
DocumentMeta is a CouchDB id/rev pair
type Follower ¶
type Follower struct {
// contains filtered or unexported fields
}
Follower is the orchestrator
func NewFollower ¶
NewFollower creates a Follower on database's changes
func (*Follower) Follow ¶
func (f *Follower) Follow() (<-chan *ChangeEvent, error)
Follow starts listening to the changes feed
type GetQueryBuilder ¶
type GetQueryBuilder interface { Attachments() GetQueryBuilder AttEncodingInfo() GetQueryBuilder AttsSince([]string) GetQueryBuilder Conflicts() GetQueryBuilder DeletedConflicts() GetQueryBuilder Latest() GetQueryBuilder LocalSeq() GetQueryBuilder Meta() GetQueryBuilder OpenRevs([]string) GetQueryBuilder Rev(string) GetQueryBuilder Revs() GetQueryBuilder RevsInfo() GetQueryBuilder Build() *getQuery }
GetQueryBuilder defines the available parameter-setting functions.
type Info ¶
type Info struct { IsCompactRunning bool `json:"compact_running"` DataSize int `json:"data_size"` DocDelCount int `json:"doc_del_count"` DocCount int `json:"doc_count"` DiskSize int `json:"disk_size"` UpdateSeq string `json:"update_seq"` }
Info represents the account meta-data
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job wraps all requests
func UploadBulkDocs ¶
func UploadBulkDocs(bulkDocs *BulkDocsRequest, database *Database) (result *Job, err error)
UploadBulkDocs performs a synchronous _bulk_docs POST
type QueryBuilder ¶
QueryBuilder is used by functions implementing Cloudant API calls that have many optional parameters
type Uploader ¶
type Uploader struct { NewEdits bool // contains filtered or unexported fields }
Uploader is where Mr Smartypants live
func (*Uploader) AsyncFlush ¶
func (u *Uploader) AsyncFlush()
AsyncFlush asynchronously uploads all received documents.
func (*Uploader) BulkUploadSimple ¶
func (u *Uploader) BulkUploadSimple(docs []interface{}) ([]BulkDocsResponse, error)
BulkUploadSimple does a one-shot synchronous bulk upload
func (*Uploader) FireAndForget ¶
func (u *Uploader) FireAndForget(doc interface{})
FireAndForget adds a document to the upload queue ready for processing by the upload worker(s).
func (*Uploader) Flush ¶
func (u *Uploader) Flush()
Flush blocks until all received documents have been uploaded.
func (*Uploader) Stop ¶
func (u *Uploader) Stop()
Stop uploads all received documents and then terminates the upload worker(s)
func (*Uploader) Upload ¶
Upload adds a document to the upload queue ready for processing by the upload worker(s). A BulkJob type is returned to the client so that progress can be monitored.
func (*Uploader) UploadNow ¶
UploadNow adds a priority document to the upload queue ready for processing by the upload worker(s). Once received by a worker it triggers the upload of the entire batch (regardless of the current batch size). A BulkJob type is returned to the client so that progress can be monitored.