aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-11-18 23:03:59 -0800
committerChris Lu <chris.lu@gmail.com>2013-11-18 23:03:59 -0800
commitd0473e27d941b78079ec0d97e2c122f892f38b40 (patch)
tree83f6c987880e5125d838febf8e6694061fc397cd
parentc4a4d3609bf07f0c84ce94dc2566984825862de7 (diff)
downloadseaweedfs-d0473e27d941b78079ec0d97e2c122f892f38b40.tar.xz
seaweedfs-d0473e27d941b78079ec0d97e2c122f892f38b40.zip
refactor api: lookup file id
-rw-r--r--go/operation/delete_content.go16
-rw-r--r--go/operation/lookup_volume_id.go15
2 files changed, 19 insertions, 12 deletions
diff --git a/go/operation/delete_content.go b/go/operation/delete_content.go
index f14259ee6..89f7fd695 100644
--- a/go/operation/delete_content.go
+++ b/go/operation/delete_content.go
@@ -2,23 +2,15 @@ package operation
import (
"code.google.com/p/weed-fs/go/glog"
- "code.google.com/p/weed-fs/go/storage"
"net/http"
)
func DeleteFile(server string, fileId string) error {
- fid, parseErr := storage.ParseFileId(fileId)
- if parseErr != nil {
- return parseErr
- }
- lookup, lookupError := Lookup(server, fid.VolumeId)
- if lookupError != nil {
- return lookupError
- }
- if len(lookup.Locations) == 0 {
- return nil
+ fileUrl, err := LookupFileId(server, fileId)
+ if err != nil {
+ return err
}
- return Delete("http://" + lookup.Locations[0].PublicUrl + "/" + fileId)
+ return Delete(fileUrl)
}
func Delete(url string) error {
req, err := http.NewRequest("DELETE", url, nil)
diff --git a/go/operation/lookup_volume_id.go b/go/operation/lookup_volume_id.go
index d95a0738a..cd1d3b1bd 100644
--- a/go/operation/lookup_volume_id.go
+++ b/go/operation/lookup_volume_id.go
@@ -35,3 +35,18 @@ func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
}
return &ret, nil
}
+
+func LookupFileId(server string, fileId string) (fullUrl string, err error) {
+ fid, parseErr := storage.ParseFileId(fileId)
+ if parseErr != nil {
+ return "", parseErr
+ }
+ lookup, lookupError := Lookup(server, fid.VolumeId)
+ if lookupError != nil {
+ return "", lookupError
+ }
+ if len(lookup.Locations) == 0 {
+ return "", errors.New("File Not Found")
+ }
+ return "http://" + lookup.Locations[0].PublicUrl + "/" + fileId, nil
+}