Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-6799

Paste-and-run Go SDK example

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Test Blocker
    • None
    • None
    • None

    Description

      Can we please have a full paste-and-run code in the documentation (with package and import parts), like the one below? Maybe even start it with "go mod init couchbase.com/main" instruction.

      package main

      import (
      "fmt"
      "github.com/couchbase/gocb/v2"
      )

      func main() {
      cluster, err := gocb.Connect(
      "localhost",
      gocb.ClusterOptions

      { Username: "Administrator", Password: "password", }

      )

      if err != nil

      { panic(err) }

      // get a bucket reference
      bucket := cluster.Bucket("travel-sample")

      // get a collection reference
      collection := bucket.DefaultCollection()

      // Upsert Document
      upsertData := map[string]string{"name": "mike"}

      upsertResult, err := collection.Upsert("my-document", upsertData, &gocb.UpsertOptions{})
      if err != nil { panic(err) }

      fmt.Println(upsertResult.Cas())

      // Get Document
      getResult, err := collection.Get("my-document", &gocb.GetOptions{})
      if err != nil

      { panic(err) }

      var myContent interface{}
      if err := getResult.Content(&myContent); err != nil { panic(err) }

      fmt.Println(myContent)
      }

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              richard.smedley Richard Smedley
              oleg.kuzmin Oleg Kuzmin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty