-
-
Save chvck/e51439756b364a0ecba3f1069d3dec06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
"github.com/couchbase/gocb/v2" | |
) | |
func main() { | |
gocb.SetLogger(gocb.DefaultStdioLogger()) | |
endpoint := "cb.c3juudskkglrhi2.cloud.couchbase.com" | |
bucketName := "default" | |
username := "dave" | |
password := "Pa$$w0rd" | |
// Initialize the Connection | |
cluster, err := gocb.Connect("couchbases://"+endpoint+"", gocb.ClusterOptions{ | |
Authenticator: gocb.PasswordAuthenticator{ | |
Username: username, | |
Password: password, | |
}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
_, err = cluster.Query("SELECT 1=1", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
bucket := cluster.Bucket(bucketName) | |
err = bucket.WaitUntilReady(5*time.Second, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
col := bucket.DefaultCollection() | |
_, err = col.Upsert("test", "inavalue", &gocb.UpsertOptions{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
getResult, err := col.Get("test", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
var val interface{} | |
err = getResult.Content(&val) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("Val: %v\n", val) | |
cluster.Close(nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment