riak

package module
v0.0.0-...-21e5c7d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2012 License: BSD-3-Clause Imports: 12 Imported by: 0

README

The goal of the project is to provide a client interface to Riak database. Currently it provides the basic REST API (http://wiki.basho.com/display/RIAK/REST+API) to the Riak key/value database. This library should be considered early Alpha since it is evolving dramatically. It includes some additional experimental access patterns that use channels to make async access to a Riak easier.

CRUD API:

Put(doc Document)

Get(doc Document)

Delete(bucketName, key string)

SEACH API:

SearchBin(bucketName, index, value string) ([]string, error) 

SearchBinRange(bucketName, index string, start, end string) ([]string, error) 

SearchInt(bucketName, index string, value int) ([]string, error) 

SearchIntRange(bucketName, index string, start, end int) ([]string, error) 


An example of how to use the apis is in examples/basic.go

Documentation

Overview

Riak (http://riak.basho.com/) database client for the go programming language.

Basic Usage: package main import (

"bytes"
"riak"

)

func main() {
    r := riak.NewRiak("localhost:8098")
    // Key, Value example
    value =
    d = riak.NewDocument("test", "foo", []byte("Foo"))

    // JSON Marshal example
    td := new(TestDocument)
    td.Foo = 1
    td.Bar = "Test Document"
    doc := riak.NewDocument("test", docId, make([]byte, 0))
    doc.JSONObject = td
    err := r.Put(doc)
    td2 := new(TestDocument)
    doc.JSONObject = td2
    err = r.Get(doc)
    err = r.Delete(bucketName, "test_key")

 }

Index

Constants

View Source
const (
	INDEX_PREFIX = "X-Riak-Index-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncRiak

type AsyncRiak struct {
	Host            string
	ResponseChannel chan *RiakResponse
	RequestIndex    int
	ResponseMap     map[int]chan *RiakResponse
}

Host is the host to connect to

func NewAsyncRiak

func NewAsyncRiak(host string) *AsyncRiak

func (*AsyncRiak) Connect

func (ar *AsyncRiak) Connect() *Riak

func (*AsyncRiak) Get

func (ar *AsyncRiak) Get(doc *Document) int

The idea it we run a Get request in the background and we will then call Wait once we have to wait for the response.

func (*AsyncRiak) MarshalGet

func (ar *AsyncRiak) MarshalGet(doc *Document, mc MarshalCallback)

Normal async callback when the response is ready

func (*AsyncRiak) NextRequestId

func (ar *AsyncRiak) NextRequestId() int

func (*AsyncRiak) Put

func (ar *AsyncRiak) Put(doc *Document) int

The idea it we run a BackgroundPut request in the background and we will then call Wait once we have to wait for the response.

func (*AsyncRiak) Wait

func (ar *AsyncRiak) Wait(requestId int) *RiakResponse

Wait until the request returns this repsonse

type Bucket

type Bucket struct {
	Props BucketProperties
	Keys  []string
}

Returned json mapping of a bucket response

type BucketProperties

type BucketProperties struct {
	Name            string
	N_val           int
	Allow_mult      bool
	Last_write_wins bool
	Precommit       []string
	Postcommit      []string
	Chash_keyfun    map[string]string
	Linkfun         map[string]string
	Old_vclock      int
	Young_vclock    int
	Big_vclock      int
	Small_vclock    int
	Keys            []string `json:"keys"`
}

Mapping riak json bucket properties

type ClosingBuffer

type ClosingBuffer struct {
	*bytes.Buffer
}

From: http://github.com/c141charlie/riak.go/blob/master/riak.go

func (*ClosingBuffer) Close

func (cb *ClosingBuffer) Close() (err error)

type Document

type Document struct {
	Bucket      string
	Key         string
	Value       []byte
	Links       []*Link
	BinIndexes  map[string]string
	IntIndexes  map[string]int64
	ContentType string
	JSONObject  interface{}
}

Define a basic document to reduce API calls

func NewDocument

func NewDocument(bucket, key string, value []byte) *Document

func (*Document) AddBinIndex

func (d *Document) AddBinIndex(name, value string)

func (*Document) AddIntIndex

func (d *Document) AddIntIndex(name string, value int64)

func (*Document) GetBinIndex

func (d *Document) GetBinIndex(name string) string

func (*Document) GetIntIndex

func (d *Document) GetIntIndex(name string) int64

func (*Document) RemoveBinIndex

func (d *Document) RemoveBinIndex(name string)

func (*Document) RemoveIntIndex

func (d *Document) RemoveIntIndex(name string)
type Link struct {
	Bucket string
	Key    string
	Tag    string
}

Definition of a link from one document to another

func NewLink(bucket, key, tag string) *Link

Wrapper for making Link easier.

type MarshalCallback

type MarshalCallback interface {
	Callback(interface{}, error)
}

Callback interface where the code automatically marshals the JSON

type Riak

type Riak struct {
	Host  string
	Debug bool
}

Basic riak datastructure

func NewRiak

func NewRiak(host string) *Riak

Create a new instance of the object

func (*Riak) BucketKeys

func (r *Riak) BucketKeys(bucketName string) ([]string, error)

XXX: BROKEN place holder for fixing!!!

func (*Riak) BucketURL

func (self *Riak) BucketURL(bucketName, path string) string

Centralize Bucket string building

func (*Riak) BuildRequest

func (self *Riak) BuildRequest(method, url_ string) *http.Request

Helper to wrap creating an http.Request

func (*Riak) BuildURL

func (self *Riak) BuildURL(bucketName, path string) string

Centralize string building

func (*Riak) CreateBucket

func (self *Riak) CreateBucket(bucketName string) (*Bucket, error)

Wrapper around get since get will create the bucket

func (*Riak) Delete

func (self *Riak) Delete(bucketName, key string) error

Remove an object from a bucket

func (*Riak) DeleteRW

func (self *Riak) DeleteRW(bucketName, key string, rw int) error

Delete with number of nodes to confirm before returning

func (*Riak) Get

func (self *Riak) Get(doc *Document) error

Load document

func (*Riak) GetBucket

func (r *Riak) GetBucket(bucketName string) (*Bucket, error)

Actually gets the bucket from the server and marshals the Bucket from the json that is returned

func (*Riak) GetR

func (self *Riak) GetR(doc *Document, r int) error

Read document with r number of nodes agreeing before returning

func (*Riak) MakeRequest

func (self *Riak) MakeRequest(req *http.Request) (*http.Response, error)

func (*Riak) ProcessRequest

func (self *Riak) ProcessRequest(req *http.Request) ([]byte, error)

Does all the network IO ops Consider using panic / recover http://blog.golang.org/2010/08/defer-panic-and-recover.html

func (*Riak) Put

func (self *Riak) Put(doc *Document) error

Put this document up with defaults set

func (*Riak) PutWDWReturn

func (self *Riak) PutWDWReturn(doc *Document, w, dw int, returnObject bool) error

Add/update an object to a bucket

func (*Riak) RemoveBucket

func (self *Riak) RemoveBucket(bucketName string) error

Removes a bucket from the server.

func (*Riak) SearchBin

func (r *Riak) SearchBin(bucketName, index, value string) ([]string, error)

Helper function to abstract away from details of syntax

func (*Riak) SearchBinRange

func (r *Riak) SearchBinRange(bucketName, index string, start, end string) ([]string, error)

Helper function to abstract away from details of syntax

func (*Riak) SearchIndex

func (r *Riak) SearchIndex(bucketName, index, value string) ([]string, error)

Secondary index searching

func (*Riak) SearchInt

func (r *Riak) SearchInt(bucketName, index string, value int) ([]string, error)

Helper function to abstract away from details of syntax

func (*Riak) SearchIntRange

func (r *Riak) SearchIntRange(bucketName, index string, start, end int) ([]string, error)

Helper function to abstract away from details of syntax

type RiakError

type RiakError struct {
	Text string
}

func NewError

func NewError(text string) *RiakError

func (*RiakError) Error

func (re *RiakError) Error() string

type RiakResponse

type RiakResponse struct {
	RequestId int
	Error     error
	Document  *Document
}

Channel that responses will be returned on

type StringCallback

type StringCallback interface {
	Callback(string, error)
}

Callback which just returns the JSON as a string useful

type URLBuilder

type URLBuilder struct {
	URL        string
	FirstParam bool
}

Datastucture to make building url easier

func NewURLBuilder

func NewURLBuilder(baseUrl string) *URLBuilder

Create and return an instance of URLBuilder

func (*URLBuilder) AddParam

func (u *URLBuilder) AddParam(name, param string)

Add params to url

Directories

Path Synopsis
go run ex.go
go run ex.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL