Developing lightweight computation at the DSG edge

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

[goclidote] Port AntidoteRemoveItemFromSetInBucket


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 02130510
......@@ -136,24 +136,33 @@ func AntidoteReadItemsFromSetInBucket(bucketName string, setName string) []strin
}
// AntidoteRemoveItemFromSetInBucket removes an item from a set in a bucket
func AntidoteRemoveItemFromSetInBucket(bucket string, set string, item string) bool {
request := fmt.Sprintf("http://%s/set/remove/%s/%s/%s", api_host_port, bucket, set, item)
response, err := http.Get(request)
func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemValue string) bool {
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, "")
defer client.Close()
defer response.Body.Close()
tx, err := client.StartTransaction()
errCheck(err, "")
if response.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(response.Body)
errCheck(err, "")
restReply := string(bodyBytes)
bucket := antidoteclient.Bucket{Bucket: []byte(bucketName)}
key := antidoteclient.Key(setName)
if restReply == "ok" {
return true
err = bucket.Update(tx, antidoteclient.SetRemove(key, []byte(itemValue)))
errCheck(err, "")
setVal, err := bucket.ReadSet(tx, key)
errCheck(err, "")
itemNotInSet := true
for _, v := range setVal {
if string(v) == itemValue {
itemNotInSet = false
}
}
return false
return itemNotInSet
}
// ReadDevicesFromAntidote read all the devices from Antidote using João's REST server
......
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