Documentation ¶
Index ¶
- Constants
- Variables
- func Endpoint(base url.URL, pathStr string, params url.Values) (string, error)
- func UnescapedHTMLJSONMarshal(t interface{}) ([]byte, error)
- type BulkDocsRequest
- type BulkDocsResponse
- type BulkJob
- type BulkJobI
- type Change
- type ChangeEvent
- type ChangeRow
- type ChangeRowChanges
- type ChangesQuery
- func (q *ChangesQuery) Conflicts() *ChangesQuery
- func (q *ChangesQuery) Descending() *ChangesQuery
- func (q *ChangesQuery) DocIDs(docIDs []string) *ChangesQuery
- func (q *ChangesQuery) Feed(feed string) *ChangesQuery
- func (q *ChangesQuery) Filter(filter string) *ChangesQuery
- func (q *ChangesQuery) Heartbeat(heartbeat int) *ChangesQuery
- func (q *ChangesQuery) IncludeDocs() *ChangesQuery
- func (q *ChangesQuery) Limit(lim int) *ChangesQuery
- func (q *ChangesQuery) SeqInterval(interval int) *ChangesQuery
- func (q *ChangesQuery) Since(since string) *ChangesQuery
- func (q *ChangesQuery) Style(style string) *ChangesQuery
- func (q *ChangesQuery) Timeout(timeout int) *ChangesQuery
- type Client
- func (c *Client) Destroy(databaseName string) error
- func (c *Client) Execute(job *Job)
- func (c *Client) Exists(databaseName string) (bool, error)
- func (c *Client) Info(databaseName string) (*Info, error)
- func (c *Client) List(q *DBsQuery) (*[]string, error)
- func (c *Client) LogIn() error
- func (c *Client) LogOut()
- func (c *Client) Ping() (err error)
- func (c *Client) Stop()
- func (c *Client) Use(databaseName string) (*Database, error)
- func (c *Client) UseOrCreate(databaseName string) (*Database, error)
- type ClientOption
- type CouchError
- type DBsQuery
- type Database
- func (d *Database) Bulk(batchSize int, batchMaxBytes int, flushSecs int) *Uploader
- func (d *Database) BulkEscaped(batchSize int, batchMaxBytes int, flushSecs int) *Uploader
- func (d *Database) Changes(q *ChangesQuery) (<-chan *Change, error)
- func (d *Database) Destroy(documentID, rev string) error
- func (d *Database) Get(documentID string, q *DocQuery, target interface{}) error
- func (d *Database) Index(designName, indexName string, q *IndexQuery) (<-chan []byte, error)
- func (d *Database) IndexRaw(designName, indexName string, q *IndexQuery) ([]byte, error)
- func (d *Database) Insert(document interface{}) (*DocumentMeta, error)
- func (d *Database) InsertEscaped(document interface{}) (*DocumentMeta, error)
- func (d *Database) InsertRaw(jsonDocument []byte) (*DocumentMeta, error)
- func (d *Database) List(q *ViewQuery) (<-chan []byte, error)
- func (d *Database) NewFollower(interval int) *Follower
- func (d *Database) View(designName, viewName string, q *ViewQuery) (<-chan []byte, error)
- func (d *Database) ViewRaw(designName, viewName string, q *ViewQuery) ([]byte, error)
- type DocQuery
- func (q *DocQuery) AttEncodingInfo() *DocQuery
- func (q *DocQuery) Attachments() *DocQuery
- func (q *DocQuery) AttsSince(since []string) *DocQuery
- func (q *DocQuery) Conflicts() *DocQuery
- func (q *DocQuery) DeletedConflicts() *DocQuery
- func (q *DocQuery) Latest() *DocQuery
- func (q *DocQuery) LocalSeq() *DocQuery
- func (q *DocQuery) Meta() *DocQuery
- func (q *DocQuery) OpenRevs(revs []string) *DocQuery
- func (q *DocQuery) Rev(rev string) *DocQuery
- func (q *DocQuery) Revs() *DocQuery
- func (q *DocQuery) RevsInfo() *DocQuery
- func (q *DocQuery) Skip(skip int) *DocQuery
- type DocumentMeta
- type Follower
- type IndexQuery
- func (q *IndexQuery) Bookmark(bookmark string) *IndexQuery
- func (q *IndexQuery) IncludeDocs() *IndexQuery
- func (q *IndexQuery) IncludeFields(fields []string) *IndexQuery
- func (q *IndexQuery) Limit(lim int) *IndexQuery
- func (q *IndexQuery) Query(query string) *IndexQuery
- func (q *IndexQuery) Stale() *IndexQuery
- type IndexRow
- type Info
- type Job
- type Sizes
- 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
- type ViewQuery
- func (q *ViewQuery) Conflicts() *ViewQuery
- func (q *ViewQuery) DeletedConflicts() *ViewQuery
- func (q *ViewQuery) Descending() *ViewQuery
- func (q *ViewQuery) DoNotReduce() *ViewQuery
- func (q *ViewQuery) DoNotUpdate() *ViewQuery
- func (q *ViewQuery) EndKey(endKey string) *ViewQuery
- func (q *ViewQuery) EndKeyDocID(endKeyDocID string) *ViewQuery
- func (q *ViewQuery) Group() *ViewQuery
- func (q *ViewQuery) GroupLevel(groupLevel int) *ViewQuery
- func (q *ViewQuery) IncludeDocs() *ViewQuery
- func (q *ViewQuery) InclusiveEnd() *ViewQuery
- func (q *ViewQuery) Key(key string) *ViewQuery
- func (q *ViewQuery) Keys(keys []string) *ViewQuery
- func (q *ViewQuery) Limit(lim int) *ViewQuery
- func (q *ViewQuery) Meta() *ViewQuery
- func (q *ViewQuery) R(r int) *ViewQuery
- func (q *ViewQuery) RevsInfo() *ViewQuery
- func (q *ViewQuery) Skip(skip int) *ViewQuery
- func (q *ViewQuery) Stable() *ViewQuery
- func (q *ViewQuery) Stale() *ViewQuery
- func (q *ViewQuery) StaleUpdateAfter() *ViewQuery
- func (q *ViewQuery) StartKey(startKey string) *ViewQuery
- func (q *ViewQuery) StartKeyDocID(startKeyDocID string) *ViewQuery
- func (q *ViewQuery) UpdateLazy() *ViewQuery
- type ViewRow
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 SLASHPLACEHOLDER = ",~.~.~,"
SLASHPLACEHOLDER holds string for fixing doc IDs that contain a slash
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 ¶
func UnescapedHTMLJSONMarshal ¶
UnescapedHTMLJSONMarshal marshals JSON without escaping HTML.
Types ¶
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 ChangesQuery ¶
ChangesQuery object helps build Cloudant ChangesQuery parameters
func NewChangesQuery ¶
func NewChangesQuery() *ChangesQuery
NewChangesQuery is a shortcut to create new Cloudant ChangesQuery object with no parameters
func (*ChangesQuery) Conflicts ¶
func (q *ChangesQuery) Conflicts() *ChangesQuery
Conflicts applies conflicts=true parameter to Cloudant ChangesQuery
func (*ChangesQuery) Descending ¶
func (q *ChangesQuery) Descending() *ChangesQuery
Descending applies descending=true parameter to Cloudant ChangesQuery
func (*ChangesQuery) DocIDs ¶
func (q *ChangesQuery) DocIDs(docIDs []string) *ChangesQuery
DocIDs applies doc_ids=(doc_ids) parameter to Cloudant ChangesQuery
func (*ChangesQuery) Feed ¶
func (q *ChangesQuery) Feed(feed string) *ChangesQuery
Feed applies feed=(feed) parameter to Cloudant ChangesQuery
func (*ChangesQuery) Filter ¶
func (q *ChangesQuery) Filter(filter string) *ChangesQuery
Filter applies filter=(filter) parameter to Cloudant ChangesQuery
func (*ChangesQuery) Heartbeat ¶
func (q *ChangesQuery) Heartbeat(heartbeat int) *ChangesQuery
Heartbeat applies heartbeat parameter to Cloudant ChangesQuery
func (*ChangesQuery) IncludeDocs ¶
func (q *ChangesQuery) IncludeDocs() *ChangesQuery
IncludeDocs applies include_docs=true parameter to Cloudant ChangesQuery
func (*ChangesQuery) Limit ¶
func (q *ChangesQuery) Limit(lim int) *ChangesQuery
Limit applies limit parameter to Cloudant ChangesQuery
func (*ChangesQuery) SeqInterval ¶
func (q *ChangesQuery) SeqInterval(interval int) *ChangesQuery
SeqInterval applies seq_interval parameter to Cloudant ChangesQuery
func (*ChangesQuery) Since ¶
func (q *ChangesQuery) Since(since string) *ChangesQuery
Since applies since=(since) parameter to Cloudant ChangesQuery
func (*ChangesQuery) Style ¶
func (q *ChangesQuery) Style(style string) *ChangesQuery
Style applies style=(style) parameter to Cloudant ChangesQuery
func (*ChangesQuery) Timeout ¶
func (q *ChangesQuery) Timeout(timeout int) *ChangesQuery
Timeout applies seq_interval parameter to Cloudant ChangesQuery
type Client ¶ added in v0.3.0
type Client struct {
// contains filtered or unexported fields
}
Client is the representation of a client connection
func NewClient ¶ added in v0.3.0
func NewClient(username, password, rootStrURL string, options ...ClientOption) (*Client, error)
NewClient returns a new Cloudant client
func (*Client) Execute ¶ added in v0.3.0
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 (*Client) Exists ¶ added in v0.3.0
Exists checks the existence of a specified database. Returns true if the database exists, else false.
func (*Client) Info ¶ added in v0.3.0
Info returns database information. See https://console.bluemix.net/docs/services/Cloudant/api/database.html#getting-database-details
func (*Client) LogOut ¶ added in v0.3.0
func (c *Client) LogOut()
LogOut deletes the current session.
func (*Client) Ping ¶ added in v0.3.0
Ping can be used to check whether a server is alive. It sends an HTTP HEAD request to the server's URL.
func (*Client) Stop ¶ added in v0.3.0
func (c *Client) Stop()
Stop kills all running workers. Once called the client is no longer able to execute new jobs.
type ClientOption ¶ added in v0.3.0
type ClientOption func(*Client)
ClientOption is a functional option setter for Client
func ClientConcurrency ¶ added in v0.3.0
func ClientConcurrency(workerCount int) ClientOption
ClientConcurrency overrides default workerCount Client option
func ClientHTTPClient ¶ added in v0.3.0
func ClientHTTPClient(httpClient *http.Client) ClientOption
ClientHTTPClient overrides default httpClient option
func ClientRetryCountMax ¶ added in v0.3.0
func ClientRetryCountMax(retryCountMax int) ClientOption
ClientRetryCountMax overrides default retryCountMax Client option
func ClientRetryDelayMax ¶ added in v0.3.0
func ClientRetryDelayMax(retryDelayMax int) ClientOption
ClientRetryDelayMax overrides default retryDelayMax Client option
func ClientRetryDelayMin ¶ added in v0.3.0
func ClientRetryDelayMin(retryDelayMin int) ClientOption
ClientRetryDelayMin overrides default retryDelayMin Client option
type CouchError ¶
CouchError is a server error response
func (*CouchError) Error ¶
func (e *CouchError) Error() string
Error() implements the error interface
type DBsQuery ¶
DBsQuery object helps build Cloudant DBsQuery parameters
func NewDBsQuery ¶
func NewDBsQuery() *DBsQuery
NewDBsQuery is a shortcut to create new Cloudant DBsQuery object with no parameters
func (*DBsQuery) Descending ¶
Descending applies descending=true parameter to Cloudant DBsQuery
func (*DBsQuery) InclusiveEnd ¶
InclusiveEnd applies inclusive_end=true parameter to Cloudant DBsQuery
type Database ¶
Database holds a reference to an authenticated client connection and the name of a remote database.
func (*Database) BulkEscaped ¶ added in v0.3.2
BulkEscaped returns a new bulk document uploader with escaped HTML
func (*Database) Changes ¶
func (d *Database) Changes(q *ChangesQuery) (<-chan *Change, error)
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) Index ¶ added in v0.3.4
func (d *Database) Index(designName, indexName string, q *IndexQuery) (<-chan []byte, error)
Index returns a channel of search index documents in which matching row types can be received.
func (*Database) IndexRaw ¶ added in v0.3.4
func (d *Database) IndexRaw(designName, indexName string, q *IndexQuery) ([]byte, error)
IndexRaw allows querying search indexes with arbitrary output
func (*Database) Insert ¶
func (d *Database) Insert(document interface{}) (*DocumentMeta, error)
Insert a document without escaped HTML.
func (*Database) InsertEscaped ¶
func (d *Database) InsertEscaped(document interface{}) (*DocumentMeta, error)
InsertEscaped a document with escaped HTML.
func (*Database) InsertRaw ¶
func (d *Database) InsertRaw(jsonDocument []byte) (*DocumentMeta, error)
InsertRaw posts raw input to Cloudant. Input may have json attributes '_id' and '_rev'. If no '_id' is given the database will generate one for you.
func (*Database) List ¶
List returns a channel of all documents in which matching row types can be received.
func (*Database) NewFollower ¶
NewFollower creates a Follower on database's changes.
type DocQuery ¶
DocQuery object helps build Cloudant DocQuery parameters
func NewDocQuery ¶
func NewDocQuery() *DocQuery
NewDocQuery is a shortcut to create new Cloudant DocQuery object with no parameters
func (*DocQuery) AttEncodingInfo ¶
AttEncodingInfo applies att_encoding_info=true parameter to Cloudant DocQuery
func (*DocQuery) Attachments ¶
Attachments applies attachments=true parameter to Cloudant DocQuery
func (*DocQuery) AttsSince ¶ added in v0.3.0
AttsSince applies attsSince=(since) parameter to Cloudant ViewQuery
func (*DocQuery) DeletedConflicts ¶
DeletedConflicts applies deleted_conflicts=true parameter to Cloudant DocQuery
func (*DocQuery) OpenRevs ¶ added in v0.3.0
OpenRevs applies open_revs=(revs) parameter to Cloudant DocQuery
type DocumentMeta ¶
DocumentMeta is a CouchDB id/rev pair.
type Follower ¶
type Follower struct {
// contains filtered or unexported fields
}
Follower is the orchestrator
func (*Follower) Follow ¶
func (f *Follower) Follow() (<-chan *ChangeEvent, error)
Follow starts listening to the changes feed.
type IndexQuery ¶ added in v0.3.4
IndexQuery object helps build Cloudant IndexQuery parameters
func NewIndexQuery ¶ added in v0.3.4
func NewIndexQuery() *IndexQuery
NewIndexQuery is a shortcut to create new Cloudant IndexQuery object with no parameters
func (*IndexQuery) Bookmark ¶ added in v0.3.4
func (q *IndexQuery) Bookmark(bookmark string) *IndexQuery
Bookmark applies bookmark=(bookmark) parameter to Cloudant IndexQuery
func (*IndexQuery) IncludeDocs ¶ added in v0.3.4
func (q *IndexQuery) IncludeDocs() *IndexQuery
IncludeDocs applies include_docs=true parameter to Cloudant IndexQuery
func (*IndexQuery) IncludeFields ¶ added in v0.3.4
func (q *IndexQuery) IncludeFields(fields []string) *IndexQuery
IncludeFields applies include_fields=(fields) parameter to Cloudant IndexQuery
func (*IndexQuery) Limit ¶ added in v0.3.4
func (q *IndexQuery) Limit(lim int) *IndexQuery
Limit applies limit parameter to Cloudant IndexQuery
func (*IndexQuery) Query ¶ added in v0.3.4
func (q *IndexQuery) Query(query string) *IndexQuery
Query applies q=(query) parameter to Cloudant IndexQuery
func (*IndexQuery) Stale ¶ added in v0.3.4
func (q *IndexQuery) Stale() *IndexQuery
Stale applies stale=ok parameter to Cloudant IndexQuery
type IndexRow ¶ added in v0.3.4
type IndexRow struct { ID string `json:"id"` Fields interface{} `json:"fields"` }
IndexRow contains one row from Cloudant search index
type Info ¶
type Info struct { IsCompactRunning bool `json:"compact_running"` DBName string `json:"db_name"` DiskFromatVersion int `json:"disk_format_version"` DiskSize int `json:"disk_size"` DocCount int `json:"doc_count"` DocDelCount int `json:"doc_del_count"` PurgeSeq int `json:"purge_seq"` Sizes Sizes `json:"sizes"` 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 Sizes ¶
type Sizes struct { File int `json:"file"` External int `json:"external"` Active int `json:"active"` }
Sizes represents the sizes part of database info.
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.
type ViewQuery ¶
ViewQuery object helps build Cloudant ViewQuery parameters
func NewViewQuery ¶
func NewViewQuery() *ViewQuery
NewViewQuery is a shortcut to create new Cloudant ViewQuery object with no parameters
func (*ViewQuery) DeletedConflicts ¶
DeletedConflicts applies deleted_conflicts=true parameter to Cloudant ViewQuery
func (*ViewQuery) Descending ¶
Descending applies descending=true parameter to Cloudant ViewQuery
func (*ViewQuery) DoNotReduce ¶ added in v0.3.5
DoNotReduce applies reduce=false parameter to Cloudant ViewQuery (the default value for views with reduce is true)
func (*ViewQuery) DoNotUpdate ¶
DoNotUpdate applies update=false parameter to Cloudant ViewQuery - return results without updating the view
func (*ViewQuery) EndKeyDocID ¶
EndKeyDocID applies endkey_docid=(key) parameter to Cloudant ViewQuery
func (*ViewQuery) GroupLevel ¶
GroupLevel applies group_level=(number) parameter to Cloudant ViewQuery
func (*ViewQuery) IncludeDocs ¶
IncludeDocs applies include_docs=true parameter to Cloudant ViewQuery
func (*ViewQuery) InclusiveEnd ¶
InclusiveEnd applies inclusive_end=true parameter to Cloudant ViewQuery
func (*ViewQuery) StaleUpdateAfter ¶
StaleUpdateAfter applies stale=update_after parameter to Cloudant ViewQuery
func (*ViewQuery) StartKeyDocID ¶
StartKeyDocID applies startkey_docid=(key) parameter to Cloudant ViewQuery
func (*ViewQuery) UpdateLazy ¶
UpdateLazy applies update=lazy parameter to Cloudant ViewQuery - return the view results without waiting for an update, but update them immediately after the request