hi, this is my first time using Couchbase, i’m trying basic auth and CRUD, idk but gocb return panic and exit
package main
import (
"fmt"
"gopkg.in/couchbase/gocb.v1"
)
type User struct {
Id string `json:"uid"`
Email string `json:"email"`
Interests []string `json:"interests"`
}
func main() {
cluster, _ := gocb.Connect("couchbase://192.168.1.192")
cluster.Authenticate(gocb.PasswordAuthenticator{
Username: "clusterUsername",
Password: "clusterPassword",
})
bucket, _ := cluster.OpenBucket("bucket_name", "")
fmt.Println("aman")
// bucket.Manager("", "").CreatePrimaryIndex("", true, false)
bucket.Upsert("u:kingarthur",
User{
Id: "kingarthur",
Email: "kingarthur@couchbase.com",
Interests: []string{"Holy Grail", "African Swallows"},
}, 0)
fmt.Println("amaf32n")
// Get the value back
var inUser User
bucket.Get("u:kingarthur", &inUser)
fmt.Printf("User: %v\n", inUser)
fmt.Println("amanf3a")
// Use query
query := gocb.NewN1qlQuery("SELECT * FROM bucket_name WHERE $1 IN interests")
rows, _ := bucket.ExecuteN1qlQuery(query, []interface{}{"African Swallows"})
var row interface{}
for rows.Next(&row) {
fmt.Printf("Row: %v", row)
}
}
go run :
aman
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x6c92da]
goroutine 1 [running]:
gopkg.in/couchbase/gocb%2ev1.(*Bucket).startKvOpTrace(...)
/home/grandong/go/src/gopkg.in/couchbase/gocb.v1/bucket.go:38
gopkg.in/couchbase/gocb%2ev1.(*Bucket).Upsert(0x0, 0x78db06, 0xc, 0x74e6a0, 0xc00005c5c0, 0x0, 0x0, 0x0, 0x0)
/home/grandong/go/src/gopkg.in/couchbase/gocb.v1/bucket_crud.go:75 +0x7a
main.main()
/home/grandong/Documents/Development/test/go-couchdb/main.go:26 +0x28a
exit status 2
go version go1.12.5 linux/amd64