seaweedfs/go/operation/lookup_volume_id.go

39 lines
816 B
Go
Raw Normal View History

package operation
import (
2013-02-27 06:54:22 +00:00
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
2013-01-17 08:56:56 +00:00
"encoding/json"
"errors"
_ "fmt"
"net/url"
)
type Location struct {
2013-02-10 17:44:44 +00:00
Url string `json:"url"`
PublicUrl string `json:"publicUrl"`
}
type LookupResult struct {
2013-02-10 17:44:44 +00:00
Locations []Location `json:"locations"`
Error string `json:"error"`
}
2012-09-20 09:53:23 +00:00
//TODO: Add a caching for vid here
func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
2013-01-17 08:56:56 +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
}