Developing lightweight computation at the DSG edge

Commit 776bb02f 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 925abfc4
......@@ -67,23 +67,28 @@ func AntidoteReadRegisterInBucket(bucketName string, registerName string) string
}
// AntidoteSetRegisterInBucket set a LWWW register in a bucket
func AntidoteSetRegisterInBucket(bucket string, register string, value string) bool {
request := fmt.Sprintf("http://%s/register/set/%s/%s/%s", api_host_port, bucket, register, value)
response, err := http.Get(request)
func AntidoteSetRegisterInBucket(bucketName string, registerName 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(registerName)
if restReply == "ok" {
return true
}
err = bucket.Update(tx, antidoteclient.RegPut(key, []byte(itemValue)))
errCheck(err, "")
setVal, err := bucket.ReadReg(tx, key)
errCheck(err, "")
if string(setVal[0]) == itemValue {
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