refactor lookup result types into package "operation"

This commit is contained in:
Chris Lu
2014-04-13 23:56:15 -07:00
parent f20ef922fd
commit 5878f7c3a1
2 changed files with 31 additions and 22 deletions

View File

@@ -11,12 +11,13 @@ import (
)
type Location struct {
Url string `json:"url"`
PublicUrl string `json:"publicUrl"`
Url string `json:"url,omitempty"`
PublicUrl string `json:"publicUrl,omitempty"`
}
type LookupResult struct {
Locations []Location `json:"locations"`
Error string `json:"error"`
VolumeId string `json:"volumeId,omitempty"`
Locations []Location `json:"locations,omitempty"`
Error string `json:"error,omitempty"`
}
func Lookup(server string, vid string) (*LookupResult, error) {
@@ -51,3 +52,20 @@ func LookupFileId(server string, fileId string) (fullUrl string, err error) {
}
return "http://" + lookup.Locations[rand.Intn(len(lookup.Locations))].PublicUrl + "/" + fileId, nil
}
func LookupVolumeIds(server string, vids []string) ([]LookupResult, error) {
values := make(url.Values)
for _, vid := range vids {
values.Add("volumeId", vid)
}
jsonBlob, err := util.Post("http://"+server+"/vol/lookup", values)
if err != nil {
return nil, err
}
var ret []LookupResult
err = json.Unmarshal(jsonBlob, &ret)
if err != nil {
return nil, err
}
return ret, nil
}