aboutsummaryrefslogtreecommitdiff
path: root/src/weed/operation/lookup_volume_id.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/weed/operation/lookup_volume_id.go')
-rw-r--r--src/weed/operation/lookup_volume_id.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/weed/operation/lookup_volume_id.go b/src/weed/operation/lookup_volume_id.go
new file mode 100644
index 000000000..ccfca67c8
--- /dev/null
+++ b/src/weed/operation/lookup_volume_id.go
@@ -0,0 +1,38 @@
+package operation
+
+import (
+ "encoding/json"
+ "errors"
+ _ "fmt"
+ "net/url"
+ "weed/storage"
+ "weed/util"
+)
+
+type Location struct {
+ Url string "url"
+ PublicUrl string "publicUrl"
+}
+type LookupResult struct {
+ Locations []Location "locations"
+ Error string "error"
+}
+
+//TODO: Add a caching for vid here
+func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
+ values := make(url.Values)
+ values.Add("volumeId", vid.String())
+ jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
+ if err != nil {
+ return nil, err
+ }
+ var ret LookupResult
+ err = json.Unmarshal(jsonBlob, &ret)
+ if err != nil {
+ return nil, err
+ }
+ if ret.Error != "" {
+ return nil, errors.New(ret.Error)
+ }
+ return &ret, nil
+}