5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CouchbaseAdvent Calendar 2015

Day 16

俺でも理解できると思ったら躓いたCouchbase Go SDKでbucket相手にhello world

Last updated at Posted at 2015-12-16

俺です。

Couchbase Server Go SDK 1.0Hello Couchbase exampleをCouchbase Server 3.0/4.0相手に動かした時、つらい目にあったのでメモを残します。

環境

2環境で試して同じエラーが出た

(1) Mac OS X

  • Couchbase Server 3.0.1
  • Go 1.4.2
  • Couchbase Server Go SDK 1.0

(2) Amazon Linux

  • Couchbase Server 4.0.1
  • Go 1.4.2
  • Couchbase Server Go SDK 1.0

ソース

package main

import (
	"fmt"

	"gopkg.in/couchbase/gocb.v1"
)

func main() {
	myCluster, _ := gocb.Connect("couchbase://localhost")
	myBucket, _ := myCluster.OpenBucket("beer-sample", "")

	var beer map[string]interface{}
	cas, _ := myBucket.Get("aass_brewery-juleol", &beer)

	beer["comment"] = "俺とお前と大五郎"
	beer["description"] = "マグロ。ご期待下さい。"
	myBucket.Replace("aass_brewery-juleol", &beer, cas, 0)
	fmt.Printf("map length `%d` value `%v` with CAS %08x", len(beer), beer, cas)
}

エラー

req.Cancel undefined !!

この更新で追加された関数 doHttpWithTimeoutreq.Cancelが使われてないってことで怒られたようです。

orenomac$ go run hello.go
# github.com/couchbase/gocb
../github.com/couchbase/gocb/bucket_http.go:262: req.Cancel undefined (type *http.Request has no field or method Cancel)

対策(2015/12/16 15:46JST時点)

まだ修正されてないようなので、 bucket_http.goの262行目をコメントアウトしてしまえばOKでした

もう一度実行

Couchbse Serverにインストールしたbeer-sampleバケットからCASの取得とkey(aass_brewery-juleol)のReplaceができました。

orenomac$ go run hello.go
map length `13` value `map[brewery_id:aass_brewery category:North American Ale comment:俺とお前と大五郎 description:マグロ。ご期待下さい。 ibu:0 name:Juleøl type:beer updated:2010-07-22 20:00:20 abv:5.9 hoge:foo bar srm:0 style:Dark American-Belgo-Style Ale upc:0]` with CAS f14915f70d9%

やったね

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?