2012-09-20 09:47:32 +00:00
|
|
|
package operation
|
|
|
|
|
|
|
|
import (
|
2013-01-17 08:15:05 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
"pkg/storage"
|
|
|
|
"pkg/util"
|
|
|
|
_ "fmt"
|
|
|
|
"errors"
|
2012-09-20 09:47:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Location struct {
|
2013-01-17 08:15:05 +00:00
|
|
|
Url string "url"
|
|
|
|
PublicUrl string "publicUrl"
|
2012-09-20 09:47:32 +00:00
|
|
|
}
|
|
|
|
type LookupResult struct {
|
2013-01-17 08:15:05 +00:00
|
|
|
Locations []Location "locations"
|
|
|
|
Error string "error"
|
2012-09-20 09:47:32 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 09:53:23 +00:00
|
|
|
//TODO: Add a caching for vid here
|
2012-09-20 09:47:32 +00:00
|
|
|
func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
|
2013-01-17 08:15:05 +00:00
|
|
|
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
|
2012-09-20 09:47:32 +00:00
|
|
|
}
|