mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor api: lookup file id
This commit is contained in:
parent
c4a4d3609b
commit
d0473e27d9
|
@ -2,23 +2,15 @@ package operation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/weed-fs/go/glog"
|
"code.google.com/p/weed-fs/go/glog"
|
||||||
"code.google.com/p/weed-fs/go/storage"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteFile(server string, fileId string) error {
|
func DeleteFile(server string, fileId string) error {
|
||||||
fid, parseErr := storage.ParseFileId(fileId)
|
fileUrl, err := LookupFileId(server, fileId)
|
||||||
if parseErr != nil {
|
if err != nil {
|
||||||
return parseErr
|
return err
|
||||||
}
|
}
|
||||||
lookup, lookupError := Lookup(server, fid.VolumeId)
|
return Delete(fileUrl)
|
||||||
if lookupError != nil {
|
|
||||||
return lookupError
|
|
||||||
}
|
|
||||||
if len(lookup.Locations) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return Delete("http://" + lookup.Locations[0].PublicUrl + "/" + fileId)
|
|
||||||
}
|
}
|
||||||
func Delete(url string) error {
|
func Delete(url string) error {
|
||||||
req, err := http.NewRequest("DELETE", url, nil)
|
req, err := http.NewRequest("DELETE", url, nil)
|
||||||
|
|
|
@ -35,3 +35,18 @@ func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
|
||||||
}
|
}
|
||||||
return &ret, nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue