goriak.v2: gopkg.in/zegl/goriak.v2 Index | Examples | Files

package goriak

import "gopkg.in/zegl/goriak.v2"

Package goriak is a Golang driver for Riak KV. Goriak offers simple ways of binding your Go datatypes and values to Riak.

Goriaks specially is dealing with Riak KV Data Types (http://docs.basho.com/riak/kv/2.1.4/developing/data-types/) and allowing Marshal/Unmarshal of Go structs into Riak Maps.

Index

Examples

Package Files

auto_map.go auto_map_decode.go auto_map_encode.go client.go counter.go flag.go goriak.go index.go json.go map_operation.go options.go query.go query_builder.go query_consistency.go raw.go register.go set.go siblings.go value.go

func NewMapOperation Uses

func NewMapOperation() riak.MapOperation

NewMapOperation returns a new riak.MapOperation that you can for advanced Riak operations

type Command Uses

type Command struct {
    // contains filtered or unexported fields
}

Command is the main query builder object

func Bucket Uses

func Bucket(bucket, bucketType string) Command

Bucket specifies the bucket and bucket type that your following command will be performed on.

func (Command) AddToIndex Uses

func (c Command) AddToIndex(key, value string) Command

func (Command) AllKeys Uses

func (c Command) AllKeys(callback func([]string) error) Command

AllKeys returns all keys in the set bucket. The response will be sent in multiple batches to callback

func (Command) ConflictResolver Uses

func (c Command) ConflictResolver(fn func([]ConflictObject) ResolvedConflict) Command

func (Command) Delete Uses

func (c Command) Delete(key string) Command

Delete deletes the value stored as key

func (Command) Get Uses

func (c Command) Get(key string, output interface{}) Command

Get retreives a Map from Riak. Get performs automatic conversion from Riak Maps to your Go datatype. See Set() for more information.

func (Command) GetJSON Uses

func (c Command) GetJSON(key string, output interface{}) Command

GetJSON is the same as GetRaw, but with automatic JSON unmarshalling

func (Command) GetRaw Uses

func (c Command) GetRaw(key string, output *[]byte) Command

GetRaw retreives key as a []byte. The output will be written to output by Run().

func (Command) IndexContinuation Uses

func (c Command) IndexContinuation(continuation []byte) Command

func (Command) Key Uses

func (c Command) Key(key string) Command

Key specifies the Riak key that following commands such as Get() and MapOperation()

func (Command) KeysInIndex Uses

func (c Command) KeysInIndex(indexName, indexValue string, callback func(SecondaryIndexQueryResult)) Command

KeysInIndex returns all keys in the index indexName that has the value indexValue The values will be returned to the callbak function When all keys have been returned SecondaryIndexQueryResult.IsComplete will be true

func (Command) Limit Uses

func (c Command) Limit(limit uint32) Command

Limit sets the limit returned in KeysInIndex A limit of 0 means unlimited

func (Command) MapOperation Uses

func (c Command) MapOperation(op riak.MapOperation, context []byte) Command

MapOperation takes a riak.MapOperation so that you can run custom commands on your Riak Maps

func (Command) Run Uses

func (c Command) Run(session *Session) (*Result, error)

Run performs the action built in Command and runs it against the Riak connection specified by Session.

func (Command) Set Uses

func (c Command) Set(val interface{}) Command

Set automatically converts your Go datatype to the equivalent type in Riak

|  Go Type   | Riak Type |
|------------|-----------|
| struct     | map       |
| string     | register  |
| [n]byte    | register  |
| []byte     | register  |
| []slice    | set       |
| []slice    | set       |
| [][]byte   | set       |
| map        | map       |
| time.Time  | register  |

func (Command) SetJSON Uses

func (c Command) SetJSON(value interface{}) Command

SetJSON saves value as key in the bucket bucket/bucketType Values can automatically be added to indexes with the struct tag goriakindex

func (Command) SetRaw Uses

func (c Command) SetRaw(value []byte) Command

SetRaw allows you to set a []byte directly to Riak. SetRaw gives you full control of the data stored, compared to SetJSON and Set.

func (Command) VClock Uses

func (c Command) VClock(vclock []byte) Command

func (Command) WithDw Uses

func (c Command) WithDw(dw uint32) Command

WithDw sets the amount of nodes required to report successfully writes to backend storage. Used with Set(), SetRaw(), SetJSON(), and Delete()

func (Command) WithPr Uses

func (c Command) WithPr(pr uint32) Command

WithPr sets the amount of primary nodes required to report back during reads. Used with Get(), GetRaw(), GetJSON(), and Delete().

func (Command) WithPw Uses

func (c Command) WithPw(pw uint32) Command

WithPw sets the amount of primary nodes required to report back during writes. Used with Set(), SetRaw(), SetJSON(), and Delete().

func (Command) WithR Uses

func (c Command) WithR(r uint32) Command

WithR sets the amount of nodes required to report back during reads. Used with Get(), GetRaw(), GetJSON(), and Delete().

func (Command) WithRw Uses

func (c Command) WithRw(rw uint32) Command

WithRw sets the amount fo nodes required to report successful deletes from backend storage. Used with Delete().

func (Command) WithW Uses

func (c Command) WithW(w uint32) Command

WithW sets the amount of nodes required to report back during writes. Used with Set(), SetRaw(), SetJSON(), and Delete().

type ConflictObject Uses

type ConflictObject struct {
    Value        []byte
    VClock       []byte
    LastModified time.Time
}

func (ConflictObject) GetResolved Uses

func (r ConflictObject) GetResolved() ResolvedConflict

GetResolved creates a ResolvedConflict object

type ConflictResolver Uses

type ConflictResolver interface {
    ConflictResolver([]ConflictObject) ResolvedConflict
}

The ConflictResolver interface is used to solve conflicts when using Get() and GetJSON(). All versions will be sent to your ConflictResolver method. Return the (merged) version that you want to keep.

Code:


// For this to work you need to activate allow_mult on your bucket type
// http://docs.basho.com/riak/kv/2.2.0/developing/usage/conflict-resolution/

session, _ := Connect(ConnectOpts{
    Address: "127.0.0.1",
})

key := "object-1"

// Save the same object without using .VClock() causing a conflict
_, err := Bucket("bucket", "tests").Key(key).SetJSON("hello").Run(session)

if err != nil {
    log.Println(err)
}

_, err = Bucket("bucket", "tests").Key(key).SetJSON("worlds of conflicts!").Run(session)

if err != nil {
    log.Println(err)
}

// Our conflict resolver object
resolver := func(objs []ConflictObject) ResolvedConflict {
    // Decide how to pick the result. We'll use len() to pick the longest value
    var maxObject ConflictObject
    var maxValue int

    for _, o := range objs {
        if len(o.Value) > maxValue {
            maxObject = o
            maxValue = len(o.Value)
        }
    }

    // Convert directly to a ResolvedConflict object
    return maxObject.GetResolved()
}

// Get your object
var res string
_, err = Bucket("bucket", "tests").
    ConflictResolver(resolver).
    GetJSON(key, &res).
    Run(session)

if err != nil {
    log.Println(err)
}

// res will now contain the longest value
log.Println(res)

type ConnectOpts Uses

type ConnectOpts struct {
    // Both Address and Addresses should be on the form HOST|IP[:PORT]
    Address   string   // Address to a single Riak host. Will be used in case Addresses is empty
    Addresses []string // Addresses to all Riak hosts.
}

ConnectOpts are the available options for connecting to your Riak instance

type Counter Uses

type Counter struct {
    // contains filtered or unexported fields
}

Counter is a wapper to handle Riak Counters Counter needs to be initialized by GetMap() to fully function

func NewCounter Uses

func NewCounter() *Counter

NewCounter returns a partial Counter Counters returned by NewCounter() can only be updated with SetMap(). Counter.Exec() will not work on counters returned by NewCounter()

func (*Counter) Exec Uses

func (c *Counter) Exec(client *Session) error

Exec saves changes made to the Counter to Riak Exec only works on Counters initialized by GetMap() If the commad succeeds the counter will be updated with the value in the response from Riak

func (*Counter) Increase Uses

func (c *Counter) Increase(i int64) *Counter

Increase the value in the Counter by i The value in Counter.Value() will be updated directly Increase() will not save the changes to Riak directly

func (Counter) MarshalJSON Uses

func (c Counter) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the JSON interface

func (*Counter) UnmarshalJSON Uses

func (c *Counter) UnmarshalJSON(data []byte) error

UnmarshalJSON satisfies the JSON interface

func (*Counter) Value Uses

func (c *Counter) Value() int64

Value returns the value in the Counter

type Flag Uses

type Flag struct {
    // contains filtered or unexported fields
}

func NewFlag Uses

func NewFlag() *Flag

func (*Flag) Exec Uses

func (f *Flag) Exec(client *Session) error

func (Flag) MarshalJSON Uses

func (f Flag) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the JSON interface

func (*Flag) Set Uses

func (f *Flag) Set(val bool) *Flag

func (*Flag) UnmarshalJSON Uses

func (f *Flag) UnmarshalJSON(data []byte) error

UnmarshalJSON satisfies the JSON interface

func (*Flag) Value Uses

func (f *Flag) Value() bool

type Register Uses

type Register struct {
    // contains filtered or unexported fields
}

func NewRegister Uses

func NewRegister() *Register

func (*Register) Exec Uses

func (r *Register) Exec(client *Session) error

func (Register) MarshalJSON Uses

func (r Register) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the JSON interface

func (*Register) Set Uses

func (r *Register) Set(val []byte) *Register

func (*Register) SetString Uses

func (r *Register) SetString(val string) *Register

func (*Register) String Uses

func (r *Register) String() string

func (*Register) UnmarshalJSON Uses

func (r *Register) UnmarshalJSON(data []byte) error

UnmarshalJSON satisfies the JSON interface

func (*Register) Value Uses

func (r *Register) Value() []byte

type ResolvedConflict Uses

type ResolvedConflict struct {
    Value  []byte
    VClock []byte
}

type Result Uses

type Result struct {
    NotFound     bool   // Wether or not the item was not found when using Get, GetJSON, or GetRaw.
    Key          string // Returns your automatically generated key when using Set, SetJSON, or SetRaw.
    Context      []byte // Returns the Riak Context used in map operations. Is set when using Get.
    VClock       []byte
    Continuation []byte // Continuation in case of SecondaryIndex queries
}

Result contains your query result data from Run()

type SecondaryIndexQueryResult Uses

type SecondaryIndexQueryResult struct {
    Key        string
    IsComplete bool
}

SecondaryIndexQueryResult is the items sent to the callback function used by KeysInIndex

type Session Uses

type Session struct {
    // contains filtered or unexported fields
}

Session holds the connection to Riak

func Connect Uses

func Connect(opts ConnectOpts) (*Session, error)

Connect creates a new Riak connection. See ConnectOpts for the available options.

type Set Uses

type Set struct {
    // contains filtered or unexported fields
}

Set is a special type to make it easier to work with Riak Sets in Go.

Code:


session, _ := Connect(ConnectOpts{
    Address: "127.0.0.1",
})

type Article struct {
    Tags *Set

    Context []byte `goriak:"goriakcontext"`
}

// Initializing a new Article and the Set within
art := Article{
    Tags: NewSet(),
}

riakKey := "article-1"

// Adding the tags "one" and "two"
art.Tags.AddString("one")
art.Tags.AddString("two")

_, err := Bucket("bucket", "bucketType").Key(riakKey).Set(art).Run(session)

if err != nil {
    // ..
}

// Retreiving from Riak
var getArt Article
_, err = Bucket("bucket", "bucketType").Get(riakKey, &getArt).Run(session)

if err != nil {
    // ..
}

// Adding one extra tag.
// Multiple AddString() and RemoveString() can be chained together before calling Exec().
err = getArt.Tags.AddString("three").Exec(session)

if err != nil {
    // ..
}

func NewSet Uses

func NewSet() *Set

NewSet returnes a new and empty Set. Sets returned from NewSet() can not be used with Set.Exec()

func (*Set) Add Uses

func (s *Set) Add(add []byte) *Set

Add adds an item to the direct value of the Set. Save the changes to Riak with Set.Exec() or SetMap().

func (*Set) AddString Uses

func (s *Set) AddString(add string) *Set

AddString is a shortcut to Add

func (*Set) Exec Uses

func (s *Set) Exec(client *Session) error

Exec executes the diff created by Add() and Remove(), and saves the data to Riak

func (*Set) Has Uses

func (s *Set) Has(search []byte) bool

Has returns true if search is a value in the set

func (*Set) HasString Uses

func (s *Set) HasString(search string) bool

HasString returns true if search is a value in the set

func (Set) MarshalJSON Uses

func (s Set) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the JSON interface

func (*Set) Remove Uses

func (s *Set) Remove(remove []byte) *Set

Remove deletes an item to the direct value of the Set. Save the changes to Riak with Set.Exec() or SetMap().

func (*Set) RemoveString Uses

func (s *Set) RemoveString(remove string) *Set

RemoveString is a shortcut to Remove

func (*Set) Strings Uses

func (s *Set) Strings() []string

Strings returns the same data as Value(), but encoded as strings

func (*Set) UnmarshalJSON Uses

func (s *Set) UnmarshalJSON(data []byte) error

UnmarshalJSON satisfies the JSON interface

func (*Set) Value Uses

func (s *Set) Value() [][]byte

Value returnes the raw values from the Set

Package goriak imports 7 packages (graph). Updated 2017-01-20. Refresh now. Tools for package owners.