Skip to content
Go, Riak, and Protocol Buffers
Go Protocol Buffer
Find file
Latest commit 8409198 Oct 29, 2015 @indykish indykish Merge pull request #66 from mrb/more_comments
Fix function name in comment
Failed to load latest commit information.
test/integration integration test tweaks Aug 6, 2013
.codeclimate.yml Exclude tests and generate pb files Jun 19, 2015
.gitignore cleaned up readme, renamed file, added doc.go and moved example to it Jun 21, 2013
LICENSE Initial May 17, 2012
README.md Update README.md Sep 15, 2015
bench_test.go New Filenames Jun 19, 2013
bucket.go Fix function name in comment Aug 6, 2015
bucket_test.go new prepare/do interface along with internal method restructuring Aug 2, 2013
client.go Add comments Aug 6, 2015
client_test.go Simplified the closing of the client by removing the boolean flag and… Nov 12, 2013
coder.go struct int index keys have to be treated as strings Aug 3, 2013
coder_test.go coder unmarshaller. two new core methods Jun 17, 2013
decaying.go add decaying files back in Aug 6, 2013
decaying_test.go add decaying files back in Aug 6, 2013
doc.go apparently example lives in a _test file. forgotten file Jun 21, 2013
err.go addresses issue #41, among other things Aug 6, 2013
example_test.go Swapped a few Print/Println statements with Fatalf, which is Dec 4, 2013
link.go link walking Jun 22, 2013
link_test.go Remove false connect message and fix test crashes with downed server Aug 28, 2013
node.go change protobuf location May 12, 2015
object.go new prepare/do interface along with internal method restructuring Aug 2, 2013
object_test.go Remove false connect message and fix test crashes with downed server Aug 28, 2013
pool.go Change some default values, and don't increase error val on not found Aug 23, 2013
query.go new prepare/do interface along with internal method restructuring Aug 2, 2013
query_test.go Merge branch 'master' into new-interface Aug 3, 2013
request.go Restrict node error recordings to networking errors, for now Aug 27, 2013
response.go change protobuf location May 12, 2015
riak.pb.go change protobuf location May 12, 2015
riak.proto update to 1.4 riak protobuf + bug fixes May 23, 2013
riak_kv.pb.go change protobuf location May 12, 2015
riak_kv.proto update to 1.4 riak protobuf + bug fixes May 23, 2013
riak_search.pb.go change protobuf location May 12, 2015
riak_search.proto update to 1.4 riak protobuf + bug fixes May 23, 2013
server.go new prepare/do interface along with internal method restructuring Aug 2, 2013
server_test.go new prepare/do interface along with internal method restructuring Aug 2, 2013

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, 9/15/2015

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.