-
Notifications
You must be signed in to change notification settings - Fork 45
/
retrieving.go
42 lines (35 loc) · 908 Bytes
/
retrieving.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"gopkg.in/couchbase/gocb.v1"
)
// bucket reference - reuse as bucket reference in the application
var bucket *gocb.Bucket
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERROR OPENING BUCKET:", err)
}
// Create a document
key := "goDevguideExampleRetrieve"
val := "Retrieve Test Value"
_, err = bucket.Upsert(key, &val, 0)
if err != nil {
fmt.Println("ERROR CREATING DOCUMENT:", err)
}
// Retrieve Document
var retValue interface{}
_, err = bucket.Get(key, &retValue)
if err != nil {
fmt.Println("ERROR RETURNING DOCUMENT:", err)
}
fmt.Println("Document Retrieved:", retValue)
// Exiting
fmt.Println("Example Successful - Exiting")
}