Developing lightweight computation at the DSG edge

Commit eccb384a authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[goclidote-demo] Demo code interacting with Antidote Go client


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent bec1ef82
package main
import (
"fmt"
"github.com/mweberUKL/go-antidote"
)
// Host represents an Antidote server.
// The port needs to be the port of the protocol-buffer interface (usually 8087)
// AntidoteAddItemToSetInBucket save an item to a set in a bucketdcrf
func main() {
client, err := antidoteclient.NewClient(antidoteclient.Host{"127.0.0.1", 8087})
errCheck(err, "")
defer client.Close()
tx, err := client.StartTransaction()
errCheck(err, "")
bucket := antidoteclient.Bucket{[]byte("bands")}
key := antidoteclient.Key("beatles")
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte("john")))
errCheck(err, "")
setVal, err := bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(1)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte("paul")))
errCheck(err, "")
setVal, err = bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(2)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte("george")))
errCheck(err, "")
setVal, err = bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(3)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte("ringo")))
errCheck(err, "")
setVal, err = bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(4)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = tx.Commit()
errCheck(err, "")
}
// Panic on error
func errCheck(err error, message string) {
if err != nil {
fmt.Println(message)
panic(err)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment