Developing lightweight computation at the DSG edge

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

[goclidote] Port AntidoteReadItemsFromSetInBucket


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 1d248756
package goclidote
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
......@@ -112,21 +111,25 @@ func AntidoteRemoveRegisterInBucket(bucket string, register string) bool {
}
// AntidoteReadItemsFromSetInBucket read items from a set in a bucket
func AntidoteReadItemsFromSetInBucket(bucket string, set string) []string {
request := fmt.Sprintf("http://%s/set/read/%s/%s", api_host_port, bucket, set)
response, err := http.Get(request)
errCheck(err, "")
func AntidoteReadItemsFromSetInBucket(bucketName string, setName string) []string {
var items []string
defer response.Body.Close()
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, "")
defer client.Close()
if response.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(response.Body)
errCheck(err, "")
tx, err := client.StartTransaction()
errCheck(err, "")
err = json.Unmarshal(bodyBytes, &items)
errCheck(err, "")
bucket := antidoteclient.Bucket{Bucket: []byte(bucketName)}
key := antidoteclient.Key(setName)
setVal, err := bucket.ReadSet(tx, key)
errCheck(err, "")
for _, v := range setVal {
items = append(items, string(v))
}
return items
......
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