A newer version of this documentation is available.

View Latest

Managing connections

Instantiate a new Cluster object.

Configuring the client

To configure the client, instantiate a new Cluster object:

myCluster, _ := gocb.Connect("couchbase://")

Connecting to a bucket

To connect to a bucket, call the OpenBucket() method against your Cluster instance, passing in the name of the bucket that you want to connect to, along with any password. If a blank bucket name is specified, the default bucket is opened. The following example shows how to connect to a bucket:

myBucket, _ := myCluster.OpenBucket("beer-sample", "")

In addition to the bucket name, you can optionally include the bucket password if one has been defined, as shown in the following example:

myBucket, _ := myCluster.OpenBucket("default", "password");

Configuring SSL

To configure SSL, pass an SSL scheme with your connection string when creating your cluster object.

myCluster, _ := gocb.Connect("couchbases://")
myBucket, _ := myCluster.OpenBucket("default", "")