A bucket is NOT CLOSED on the example of use

A bucket is NOT CLOSED on a example of use on Start Using the SDK.

defer bucket.Close() should be added after bucket, _ := cluster.OpenBucket("bucketname", "")


package main

import (

type User struct {
	Id string `json:"uid"`
	Email string `json:"email"`
	Interests []string `json:"interests"`

func main() {
        cluster, _ := gocb.Connect("couchbase://localhost")
            Username: "USERNAME",
            Password: "PASSWORD",
        bucket, _ := cluster.OpenBucket("bucketname", "")
        defer bucket.Close()
        bucket.Manager("", "").CreatePrimaryIndex("", true, false)
                        Id: "kingarthur",
                        Email: "kingarthur@couchbase.com",
                        Interests: []string{"Holy Grail", "African Swallows"},
                }, 0)
        // Get the value back
        var inUser User
        bucket.Get("u:kingarthur", &inUser)
        fmt.Printf("User: %v\n", inUser)
        // Use query
        query := gocb.NewN1qlQuery("SELECT * FROM bucketname WHERE $1 IN interests")
        rows, _ := bucket.ExecuteN1qlQuery(query, []interface{}{"African Swallows"})
        var row interface{}
        for rows.Next(&row) {
                fmt.Printf("Row: %v", row)
1 Like

Hey @usk,

I’ve notified our documentation team and they are on it! Thanks a lot for pointing this out.

Cheers, Brett

1 Like