Documentation ¶
Overview ¶
A smart client for go.
Usage:
client, err := couchbase.Connect("http://myserver:8091/") handleError(err) pool, err := client.GetPool("default") handleError(err) bucket, err := pool.GetBucket("MyAwesomeBucket") handleError(err) ...
or a shortcut for the bucket directly
bucket, err := couchbase.GetBucket("http://myserver:8091/", "default", "default")
in any case, you can specify authentication credentials using standard URL userinfo syntax:
b, err := couchbase.GetBucket("http://bucketname:bucketpass@myserver:8091/", "default", "bucket")
Index ¶
- Constants
- Variables
- func CleanupHost(h, commonSuffix string) string
- func FindCommonSuffix(input []string) string
- type AuthHandler
- type Bucket
- func (b *Bucket) Add(k string, exp int, v interface{}) (added bool, err error)
- func (b *Bucket) AddRaw(k string, exp int, v []byte) (added bool, err error)
- func (b *Bucket) Close()
- func (b Bucket) CommonAddressSuffix() string
- func (b *Bucket) Delete(k string) error
- func (b *Bucket) DeleteDDoc(docname string) error
- func (b *Bucket) Do(k string, f func(mc *memcached.Client, vb uint16) error) error
- func (b *Bucket) Get(k string, rv interface{}) error
- func (b *Bucket) GetBulk(keys []string) (map[string]*gomemcached.MCResponse, error)
- func (b *Bucket) GetDDoc(docname string, into interface{}) error
- func (b *Bucket) GetDDocs() (DDocsResult, error)
- func (b *Bucket) GetPool() *Pool
- func (b *Bucket) GetRaw(k string) ([]byte, error)
- func (b *Bucket) GetStats(which string) map[string]map[string]string
- func (b *Bucket) Gets(k string, rv interface{}, caso *uint64) error
- func (b *Bucket) GetsRaw(k string) (data []byte, flags int, cas uint64, err error)
- func (b *Bucket) Incr(k string, amt, def uint64, exp int) (uint64, error)
- func (b Bucket) NodeAddresses() []string
- func (b *Bucket) Observe(k string) (result memcached.ObserveResult, err error)
- func (b *Bucket) PutDDoc(docname string, value interface{}) error
- func (b *Bucket) Set(k string, exp int, v interface{}) error
- func (b *Bucket) SetRaw(k string, exp int, v []byte) error
- func (b *Bucket) StartTapFeed(args *memcached.TapArguments) (*TapFeed, error)
- func (b *Bucket) Update(k string, exp int, callback UpdateFunc) error
- func (b *Bucket) VBHash(key string) uint32
- func (b *Bucket) View(ddoc, name string, params map[string]interface{}) (ViewResult, error)
- func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{}, vres interface{}) error
- func (b *Bucket) ViewURL(ddoc, name string, params map[string]interface{}) (string, error)
- func (b *Bucket) WaitForPersistence(k string, cas uint64, deletion bool) error
- func (b *Bucket) Write(k string, flags, exp int, v interface{}, opt WriteOptions) (err error)
- func (b *Bucket) WriteUpdate(k string, exp int, callback WriteUpdateFunc) error
- type Client
- type DDoc
- type DDocJSON
- type DDocRow
- type DDocsResult
- type DocId
- type Node
- type Pool
- type Pools
- type RestPool
- type TapFeed
- type UpdateFunc
- type ViewDefinition
- type ViewError
- type ViewResult
- type ViewRow
- type WriteOptions
- type WriteUpdateFunc
Constants ¶
const ( // If set, value is raw []byte or nil; don't JSON-encode it. Raw = WriteOptions(1 << iota) // If set, Write fails with ErrKeyExists if key already has a value. AddOnly // If set, Write will wait until the value is written to disk. Persist // If set, Write will wait until the value is available to be indexed by views. // (In Couchbase Server 2.x, this has the same effect as the Persist flag.) Indexable )
const UpdateCancel = memcached.CASQuit
Return this as the error from an UpdateFunc to cancel the Update operation.
Variables ¶
var ConnPoolTimeout = time.Hour * 24 * 30
var ErrKeyExists = errors.New("Key exists")
Error returned from Write with AddOnly flag, when key already exists in the bucket.
var ErrOverwritten = errors.New("Overwritten")
Returned from WaitForPersistence (or Write, if the Persistent or Indexable flag is used) if the value has been overwritten by another before being persisted.
var ErrTimeout = errors.New("Timeout")
Returned from WaitForPersistence (or Write, if the Persistent or Indexable flag is used) if the value hasn't been persisted by the timeout interval
var HttpClient = http.DefaultClient
The HTTP Client To Use
var MaxBulkRetries = 10
Maximum number of times to retry a chunk of a bulk get on error.
var TimeoutError = errors.New("timeout waiting to build connection")
Functions ¶
func CleanupHost ¶
Return the hostname with the given suffix removed.
func FindCommonSuffix ¶
Find the longest common suffix from the given strings.
Types ¶
type AuthHandler ¶
Auth callback gets the auth username and password for the given bucket.
type Bucket ¶
type Bucket struct { AuthType string `json:"authType"` Capabilities []string `json:"bucketCapabilities"` CapabilitiesVersion string `json:"bucketCapabilitiesVer"` Type string `json:"bucketType"` Name string `json:"name"` NodeLocator string `json:"nodeLocator"` Nodes []Node `json:"nodes"` Quota map[string]float64 `json:"quota,omitempty"` Replicas int `json:"replicaNumber"` Password string `json:"saslPassword"` URI string `json:"uri"` StreamingURI string `json:"streamingUri"` LocalRandomKeyURI string `json:"localRandomKeyUri,omitempty"` UUID string `json:"uuid"` DDocs struct { URI string `json:"uri"` } `json:"ddocs,omitempty"` VBucketServerMap struct { HashAlgorithm string `json:"hashAlgorithm"` NumReplicas int `json:"numReplicas"` ServerList []string `json:"serverList"` VBucketMap [][]int `json:"vBucketMap"` } `json:"vBucketServerMap"` BasicStats map[string]interface{} `json:"basicStats,omitempty"` Controllers map[string]interface{} `json:"controllers,omitempty"` // contains filtered or unexported fields }
An individual bucket. Herein lives the most useful stuff.
func (*Bucket) Add ¶
Adds a value to this bucket; like Set except that nothing happens if the key exists. The value will be serialized into a JSON document.
func (*Bucket) AddRaw ¶
Adds a value to this bucket; like SetRaw except that nothing happens if the key exists. The value will be stored as raw bytes.
func (*Bucket) Close ¶
func (b *Bucket) Close()
Mark this bucket as no longer needed, closing connections it may have open.
func (Bucket) CommonAddressSuffix ¶
Get the longest common suffix of all host:port strings in the node list.
func (*Bucket) DeleteDDoc ¶
Delete a design document.
func (*Bucket) Do ¶
Execute a function on a memcached connection to the node owning key "k"
Note that this automatically handles transient errors by replaying your function on a "not-my-vbucket" error, so don't assume your command will only be executed only once.
func (*Bucket) Get ¶
Get a value from this bucket. The value is expected to be a JSON stream and will be deserialized into rv.
func (*Bucket) GetBulk ¶
func (b *Bucket) GetBulk(keys []string) (map[string]*gomemcached.MCResponse, error)
func (*Bucket) GetStats ¶
Get a set of stats from all servers.
Returns a map of server ID -> map of stat key to map value.
func (*Bucket) Gets ¶
Get a value from this bucket, including its CAS counter. The value is expected to be a JSON stream and will be deserialized into rv.
func (Bucket) NodeAddresses ¶
Get the (sorted) list of memcached node addresses (hostname:port).
func (*Bucket) StartTapFeed ¶
Creates and starts a new Tap feed
func (*Bucket) Update ¶
func (b *Bucket) Update(k string, exp int, callback UpdateFunc) error
Safe update of a document, avoiding conflicts by using CAS.
The callback function will be invoked with the current raw document contents (or nil if the document doesn't exist); it should return the updated raw contents (or nil to delete.) If it decides not to change anything it can return UpdateCancel as the error.
If another writer modifies the document between the get and the set, the callback will be invoked again with the newer value.
func (*Bucket) View ¶
func (b *Bucket) View(ddoc, name string, params map[string]interface{}) (ViewResult, error)
Execute a view.
The ddoc parameter is just the bare name of your design doc without the "_design/" prefix.
Parameters are string keys with values that correspond to couchbase view parameters. Primitive should work fairly naturally (booleans, ints, strings, etc...) and other values will attempt to be JSON marshaled (useful for array indexing on on view keys, for example).
Example:
res, err := couchbase.View("myddoc", "myview", map[string]interface{}{ "group_level": 2, "start_key": []interface{}{"thing"}, "end_key": []interface{}{"thing", map[string]string{}}, "stale": false, })
func (*Bucket) ViewCustom ¶
func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{}, vres interface{}) error
Perform a view request that can map row values to a custom type.
See the source to View for an example usage.
func (*Bucket) WaitForPersistence ¶
WaitForPersistence waits for an item to be considered durable.
Besides transport errors, ErrOverwritten may be returned if the item is overwritten before it reaches durability. ErrTimeout may occur if the item isn't found durable in a reasonable amount of time.
func (*Bucket) Write ¶
func (b *Bucket) Write(k string, flags, exp int, v interface{}, opt WriteOptions) (err error)
General-purpose value setter.
The Set, Add and Delete methods are just wrappers around this. The interpretation of `v` depends on whether the `Raw` option is given. If it is, v must be a byte array or nil. (A nil value causes a delete.) If `Raw` is not given, `v` will be marshaled as JSON before being written. It must be JSON-marshalable and it must not be nil.
func (*Bucket) WriteUpdate ¶
func (b *Bucket) WriteUpdate(k string, exp int, callback WriteUpdateFunc) error
Safe update of a document, avoiding conflicts by using CAS. WriteUpdate is like Update, except that the callback can return a set of WriteOptions, of which Persist and Indexable are recognized: these cause the call to wait until the document update has been persisted to disk and/or become available to index.
type Client ¶
type Client struct { BaseURL *url.URL Info Pools Statuses [256]uint64 // contains filtered or unexported fields }
The couchbase client gives access to all the things.
func Connect ¶
Connect to a couchbase cluster. An authentication handler will be created from the userinfo in the URL if provided.
func ConnectWithAuth ¶
func ConnectWithAuth(baseU string, ah AuthHandler) (c Client, err error)
ConnectWithAuth connects to a couchbase cluster with the given authentication handler.
type DDocJSON ¶
type DDocJSON struct { Language string `json:"language,omitempty"` Views map[string]ViewDefinition `json:"views"` }
type DDocsResult ¶
type DDocsResult struct {
Rows []DDocRow `json:"rows"`
}
type Node ¶
type Node struct { ClusterCompatibility int `json:"clusterCompatibility"` ClusterMembership string `json:"clusterMembership"` CouchAPIBase string `json:"couchApiBase"` Hostname string `json:"hostname"` InterestingStats map[string]float64 `json:"interestingStats,omitempty"` MCDMemoryAllocated float64 `json:"mcdMemoryAllocated"` MCDMemoryReserved float64 `json:"mcdMemoryReserved"` MemoryFree float64 `json:"memoryFree"` MemoryTotal float64 `json:"memoryTotal"` OS string `json:"os"` Ports map[string]int `json:"ports"` Status string `json:"status"` Uptime int `json:"uptime,string"` Version string `json:"version"` ThisNode bool `json:"thisNode,omitempty"` }
A computer in a cluster running the couchbase software.
type Pool ¶
type Pool struct { BucketMap map[string]Bucket Nodes []Node BucketURL map[string]string `json:"buckets"` // contains filtered or unexported fields }
A pool of nodes and buckets.
type TapFeed ¶
type TapFeed struct { C <-chan memcached.TapEvent // contains filtered or unexported fields }
A Tap feed. Events from the bucket can be read from the channel 'C'. Remember to call Close() on it when you're done, unless its channel has closed itself already.
type UpdateFunc ¶
A callback function to update a document
type ViewDefinition ¶
type ViewResult ¶
type WriteUpdateFunc ¶
type WriteUpdateFunc func(current []byte) (updated []byte, opt WriteOptions, err error)
A callback function to update a document