Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Go, Riak, and Protocol Buffers

Merge pull request #58 from jcoene/master

Fix null pointer dereference when server goes away
latest commit 7e9829370c
Michael Bernstein authored
Failed to load latest commit information.
test/integration integration test tweaks
.gitignore cleaned up readme, renamed file, added doc.go and moved example to it
LICENSE Initial
README.md Update README.md
bench_test.go New Filenames
bucket.go new prepare/do interface along with internal method restructuring
bucket_test.go new prepare/do interface along with internal method restructuring
client.go Simplified the closing of the client by removing the boolean flag and…
client_test.go Simplified the closing of the client by removing the boolean flag and…
coder.go struct int index keys have to be treated as strings
coder_test.go coder unmarshaller. two new core methods
decaying.go add decaying files back in
decaying_test.go add decaying files back in
doc.go apparently example lives in a _test file. forgotten file
err.go addresses issue #41, among other things
example_test.go Swapped a few Print/Println statements with Fatalf, which is
link.go link walking
link_test.go Remove false connect message and fix test crashes with downed server
node.go Fix null pointer dereference when server goes away
object.go new prepare/do interface along with internal method restructuring
object_test.go Remove false connect message and fix test crashes with downed server
pool.go Change some default values, and don't increase error val on not found
query.go new prepare/do interface along with internal method restructuring
query_test.go Merge branch 'master' into new-interface
request.go Restrict node error recordings to networking errors, for now
response.go Mutexes in place
riak.pb.go update to 1.4 riak protobuf + bug fixes
riak.proto update to 1.4 riak protobuf + bug fixes
riak_kv.pb.go update to 1.4 riak protobuf + bug fixes
riak_kv.proto update to 1.4 riak protobuf + bug fixes
riak_search.pb.go update to 1.4 riak protobuf + bug fixes
riak_search.proto update to 1.4 riak protobuf + bug fixes
server.go new prepare/do interface along with internal method restructuring
server_test.go new prepare/do interface along with internal method restructuring

README.md

This library is in dire need of help, and I can no longer maintain it. If you want to help, please open an issue. - mrb, 8/29/2014

riakpbc

A Riak Protocol Buffer Client in Go.

Notes

As of October 4, 2013 this library is considered to be in a 1.0-RC1 state, with a few documented near-production use cases.

Installation

$ go get github.com/mrb/riakpbc

Basic Usage

package main
import (
    "fmt"
    "log"
    "github.com/mrb/riakpbc"
)

func main() {
    // Initialize riakpbc against a 3 node cluster
    riak := riakpbc.NewClient([]string{"127.0.0.1:8087", "127.0.0.0:9089", "127.0.0.0:9090"})

    // Dial all the nodes.
    if err := riak.Dial(); err != nil {
        log.Fatalf("Dialing failed: %v", err)
    }

    // Set Client ID
    if _, err := riak.SetClientId("coolio"); err != nil {
        log.Fatalf("Setting client ID failed: %v", err)
    }

    // Store raw data (int, string, []byte)
    if _, err := riak.StoreObject("bucket", "other", "direct data"); err != nil {
        log.Println(err.Error())
    }

    // Fetch raw data (int, string, []byte)
    obj, err := riak.FetchObject("bucket", "other")
    if err != nil {
        log.Println(err.Error())
    }
    fmt.Println(string(obj.GetContent()[0].GetValue()))
    // Output:
    // direct data

    //-----------------------------------------
    // Alternatively prepare and Do() queries.
    //-----------------------------------------

    // Set Client ID
    opts1 := riak.NewSetClientIdRequest("coolio")
    if _, err := riak.Do(opts1); err != nil {
        log.Fatalf("Setting client ID failed: %v", err)
    }

    // Store raw data (int, string, []byte)
    opts2 := riak.NewStoreObjectRequest("bucket", "other")
    if _, err := riak.DoObject(opts2, "direct data"); err != nil {
        log.Println(err.Error())
    }

    // Fetch raw data (int, string, []byte)
    opts3 := riak.NewFetchObjectRequest("bucket", "other")
    objDo, err := riak.Do(opts3)
    if err != nil {
        log.Println(err.Error())
    }
    fmt.Println(string(objDo.(*riakpbc.RpbGetResp).GetContent()[0].GetValue()))
    // Output:
    // direct data

    // Close the connections if completely finished
    riak.Close()
}

Usage with a Coder

package main
import (
    "fmt"
    "log"
    "github.com/mrb/riakpbc"
)

// Note that structures use the special 'riak' tag to identify if they are an index or not.
// The correct _bin or _int index name gets appended based on the field type.
type ExampleData struct {
    Field1 string `riak:"index" json:"field1"`
    Field2 int    `json:"field2"`
}

func main() {
    // Initialize riakpbc against a 3 node cluster and with a JSON struct coder.
    //
    // Alternative marshallers can be built from this interface.
    coder := riakpbc.NewCoder("json", riakpbc.JsonMarshaller, riakpbc.JsonUnmarshaller)
    riakCoder := riakpbc.NewClientWithCoder([]string{"127.0.0.1:8087", "127.0.0.0:9089", "127.0.0.0:9090"}, coder)

    // Dial all the nodes.
    if err := riakCoder.Dial(); err != nil {
        log.Fatalf("Dialing failed: %v", err)
    }

    // Set Client ID
    if _, err := riakCoder.SetClientId("coolio"); err != nil {
        log.Fatalf("Setting client ID failed: %v", err)
    }

    // Store Struct (uses coder)
    data := ExampleData{
        Field1: "ExampleData1",
        Field2: 1,
    }
    if _, err := riakCoder.StoreStruct("bucket", "data", &data); err != nil {
        log.Println(err.Error())
    }

    // Fetch Struct (uses coder)
    out := &ExampleData{}
    if _, err := riakCoder.FetchStruct("bucket", "other", out); err != nil {
        log.Println(err.Error())
    }
    fmt.Println(out.Field1)
    // Output
    // ExampleData1

    //-----------------------------------------
    // Alternatively prepare and Do() queries.
    //-----------------------------------------

    // Store Struct (uses coder)
    opts1 := riakCoder.NewStoreStructRequest("bucket", "data")
    if _, err := riakCoder.DoStruct(opts1, &data); err != nil {
        log.Println(err.Error())
    }

    // Fetch Struct (uses coder)
    outDo := &ExampleData{}
    opts2 := riakCoder.NewFetchStructRequest("bucket", "other")
    if _, err := riakCoder.DoStruct(opts2, outDo); err != nil {
        log.Println(err.Error())
    }
    fmt.Println(outDo.Field1)
    // Output
    // ExampleData1

    // Close the connections if completely finished
    riakCoder.Close()
}

Documentation

http://godoc.org/github.com/mrb/riakpbc or go doc

Testing

go test

Benchmarks

go test -test.bench=".*"

Credits

License

riakpbc is distributed under the MIT License, see LICENSE file for details.

Something went wrong with that request. Please try again.