I have a widget.json file which is loaded into a document in couchbase:
{
"type": "widget",
"name": "clicker",
"description": "clicks!"
}
I also have a couchbase design document, couchbase.ddoc, for a bucket. It is registered with the name "views":
{
"_id": "_design/accesscheck",
"language": "javascript",
"views": {
"all_widgets": {
"map": "function(doc, meta) { if(doc.type == 'widget') { emit(meta.id, doc.name); } }"
}
}
}
and some golang code, using the couchbase golang API, to fetch it:
opts := map[string]interface{}{
"stale": false
}
data, _ := bucket.View("views", "all_widgets", opts)
and at this point i still have A Few Questions:
- what is the best way to determine what i can do with the "data" variable? I suspect it's a list of integer-indexed rows, each of which contains a key/value map where the value can be of different types. I see plenty of trivial examples for map[string]interface{}, but this seems to have an additional level of indirection. Easily understandable in C, IMHO, but the interface{}{} is puzzling to me.
- probably an extension of the above answer, but how can i effectively search using the design document? I would rather have the Couchbase server doing the sifting.
-
some of the Get() examples pass in a struct type i.e.
type User struct { Name string `json:"name"` Id string `json:"id"` } err = bucket.Get("1", &user) if err != nil { log.Fatalf("Failed to get data from the cluster (%s) ", err) } fmt.Printf("Got back a user with a name of (%s) and id (%s) ", user.Name, user.Id)
Is it possible to do something like this with a View()?
- does somebody know of a good way to flexibly hook the View mechanism into a net/http REST handler? Just hoping..
I didn't find these questions covered in the golang client API examples or documentation. I probably missed something. If someone has links please let me know.
Thanks for any help!