Developing lightweight computation at the DSG edge

Commit 7364fdec authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[apidote] Add two functions to set and clear LWW registers


Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent 03ecdaf9
......@@ -31,6 +31,48 @@ func AntidoteAddItemToSetInBucket(bucket string, set string, item string) bool {
return false
}
// AntidoteSetRegisterInInBucket set a LWWW register in a bucket
func AntidoteSetRegisterInInBucket(bucket string, register string, value string) bool {
request := fmt.Sprintf("http://localhost:3000/register/set/%s/%s/%s", bucket, register, value)
response, err := http.Get(request)
errCheck(err)
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(response.Body)
errCheck(err)
restReply := string(bodyBytes)
if restReply == "ok" {
return true
}
}
return false
}
// AntidoteRemoveRegisterInInBucket remove (set null) a LWWW register in a bucket
func AntidoteRemoveRegisterInInBucket(bucket string, register string) bool {
request := fmt.Sprintf("http://localhost:3000/register/set/%s/%s/\\'\\'", bucket, register)
response, err := http.Get(request)
errCheck(err)
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(response.Body)
errCheck(err)
restReply := string(bodyBytes)
if restReply == "ok" {
return true
}
}
return false
}
// AntidoteReadItemsFromSetInBucket read items from a set in a bucket
func AntidoteReadItemsFromSetInBucket(bucket string, set string) []string {
request := fmt.Sprintf("http://localhost:3000/set/read/%s/%s", bucket, set)
......
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