Developing lightweight computation at the DSG edge

Commit 757b0113 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[apidote] Move more functions to the library


Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent ab6b87a9
......@@ -5,9 +5,12 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"lightkone.guifi.net/uc-monitor-go-test/cnml"
)
// Antidote: save an item to a set in a bucket
// AntidoteAddItemToSetInBucket save an item to a set in a bucket
func AntidoteAddItemToSetInBucket(bucket string, set string, item string) bool {
request := fmt.Sprintf("http://localhost:3000/set/add/%s/%s/%s", bucket, set, item)
response, err := http.Get(request)
......@@ -28,7 +31,7 @@ func AntidoteAddItemToSetInBucket(bucket string, set string, item string) bool {
return false
}
// Antidote: read items from a set in a bucket
// 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)
response, err := http.Get(request)
......@@ -70,6 +73,21 @@ func AntidoteRemoveItemFromSetInBucket(bucket string, set string, item string) b
return false
}
// Read all the devices from Antidote using João's REST server
func ReadDevicesFromAntidote() []cnml.DeviceIpv4Adddresses {
var devices []cnml.DeviceIpv4Adddresses
for _, v := range AntidoteReadItemsFromSetInBucket("guifi", "devices") {
thisDevID, err := strconv.Atoi(v)
errCheck(err)
var thisDev cnml.DeviceIpv4Adddresses
thisDev.ID = thisDevID
devices = append(devices, thisDev)
}
return devices
}
// Panic on error
func errCheck(e error) {
if e != nil {
......
......@@ -8,7 +8,6 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"lightkone.guifi.net/uc-monitor-go-test/apidote"
"lightkone.guifi.net/uc-monitor-go-test/cnml"
......@@ -159,7 +158,7 @@ func main() {
// }
// Read current AntidoteDB devices
antidoteDevices := readDevicesFromAntidote()
antidoteDevices := apidote.ReadDevicesFromAntidote()
// Export devices and their addresses to AntidoteDB
antidoteAddDeviceSuccess := 0
......@@ -467,21 +466,6 @@ func removeDeviceFromAntidote(device cnml.DeviceIpv4Adddresses) bool {
return apidote.AntidoteRemoveItemFromSetInBucket("guifi", "devices", fmt.Sprintf("%d", device.ID))
}
// Read all the devices from Antidote using João's REST server
func readDevicesFromAntidote() []cnml.DeviceIpv4Adddresses {
var devices []cnml.DeviceIpv4Adddresses
for _, v := range apidote.AntidoteReadItemsFromSetInBucket("guifi", "devices") {
thisDevID, err := strconv.Atoi(v)
errCheck(err)
var thisDev cnml.DeviceIpv4Adddresses
thisDev.ID = thisDevID
devices = append(devices, thisDev)
}
return devices
}
// Read all the devices from Antidote using João's REST server
func readDeviceIpv4AddressesFromAntidote(device cnml.DeviceIpv4Adddresses) cnml.DeviceIpv4Adddresses {
......
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