aboutsummaryrefslogtreecommitdiff
path: root/src/weed/operation/lookup_volume_id.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-02-10 03:09:26 -0800
committerChris Lu <chris.lu@gmail.com>2013-02-10 03:09:26 -0800
commitcb4e8ec16b5c204718f1efdc1731f1bdd5698ff3 (patch)
tree47f27040c3d80e6849932bf2acf54b68c930f72b /src/weed/operation/lookup_volume_id.go
parentd3b267bac27018b7f70dfec7c258d0556fff4c14 (diff)
downloadseaweedfs-cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3.tar.xz
seaweedfs-cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3.zip
re-organize code directory structure
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
+}