Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Go, Riak, and Protocol Buffers

branch: master
Octocat-spinner-32 test integration test tweaks August 06, 2013
Octocat-spinner-32 .gitignore cleaned up readme, renamed file, added doc.go and moved example to it June 21, 2013
Octocat-spinner-32 LICENSE Initial May 17, 2012
Octocat-spinner-32 README.md Swapped a few Print/Println statements with Fatalf, which is December 04, 2013
Octocat-spinner-32 bench_test.go New Filenames June 19, 2013
Octocat-spinner-32 bucket.go new prepare/do interface along with internal method restructuring August 02, 2013
Octocat-spinner-32 bucket_test.go new prepare/do interface along with internal method restructuring August 02, 2013
Octocat-spinner-32 client.go Simplified the closing of the client by removing the boolean flag and… November 12, 2013
Octocat-spinner-32 client_test.go Simplified the closing of the client by removing the boolean flag and… November 12, 2013
Octocat-spinner-32 coder.go struct int index keys have to be treated as strings August 03, 2013
Octocat-spinner-32 coder_test.go coder unmarshaller. two new core methods June 17, 2013
Octocat-spinner-32 decaying.go add decaying files back in August 06, 2013
Octocat-spinner-32 decaying_test.go add decaying files back in August 06, 2013
Octocat-spinner-32 doc.go apparently example lives in a _test file. forgotten file June 21, 2013
Octocat-spinner-32 err.go addresses issue #41, among other things August 06, 2013
Octocat-spinner-32 example_test.go Swapped a few Print/Println statements with Fatalf, which is December 04, 2013
Octocat-spinner-32 link.go link walking June 22, 2013
Octocat-spinner-32 link_test.go Remove false connect message and fix test crashes with downed server August 28, 2013
Octocat-spinner-32 node.go Fix for #54 December 04, 2013
Octocat-spinner-32 object.go new prepare/do interface along with internal method restructuring August 02, 2013
Octocat-spinner-32 object_test.go Remove false connect message and fix test crashes with downed server August 28, 2013
Octocat-spinner-32 pool.go Change some default values, and don't increase error val on not found August 23, 2013
Octocat-spinner-32 query.go new prepare/do interface along with internal method restructuring August 02, 2013
Octocat-spinner-32 query_test.go Merge branch 'master' into new-interface August 03, 2013
Octocat-spinner-32 request.go Restrict node error recordings to networking errors, for now August 27, 2013
Octocat-spinner-32 response.go Mutexes in place June 19, 2013
Octocat-spinner-32 riak.pb.go update to 1.4 riak protobuf + bug fixes May 23, 2013
Octocat-spinner-32 riak.proto update to 1.4 riak protobuf + bug fixes May 23, 2013
Octocat-spinner-32 riak_kv.pb.go update to 1.4 riak protobuf + bug fixes May 23, 2013
Octocat-spinner-32 riak_kv.proto update to 1.4 riak protobuf + bug fixes May 23, 2013
Octocat-spinner-32 riak_search.pb.go update to 1.4 riak protobuf + bug fixes May 23, 2013
Octocat-spinner-32 riak_search.proto update to 1.4 riak protobuf + bug fixes May 23, 2013
Octocat-spinner-32 server.go new prepare/do interface along with internal method restructuring August 02, 2013
Octocat-spinner-32 server_test.go new prepare/do interface along with internal method restructuring August 02, 2013
README.md

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.