Developing lightweight computation at the DSG edge

Commit 241a5fd7 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[goclidote] Port AntidoteSetRegisterInBucket


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 776bb02f
......@@ -2,8 +2,6 @@ package goclidote
import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"uc-monitor-go-test/cnml"
......@@ -93,23 +91,28 @@ func AntidoteSetRegisterInBucket(bucketName string, registerName string, itemVal
}
// AntidoteRemoveRegisterInBucket remove (set null) a LWWW register in a bucket
func AntidoteRemoveRegisterInBucket(bucket string, register string) bool {
request := fmt.Sprintf("http://%s/register/set/%s/%s/\\'\\'", api_host_port, bucket, register)
response, err := http.Get(request)
func AntidoteRemoveRegisterInBucket(bucketName string, registerName 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(registerName)
if restReply == "ok" {
return true
}
err = bucket.Update(tx, antidoteclient.RegPut(key, []byte(nil)))
errCheck(err, "")
setVal, err := bucket.ReadReg(tx, key)
errCheck(err, "")
if string(setVal[0]) == "" {
return true
}
return false
}
......
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