You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
792 B

  1. package operation
  2. import (
  3. "encoding/json"
  4. "errors"
  5. _ "fmt"
  6. "net/url"
  7. "code.google.com/p/weed-fs/weed/storage"
  8. "code.google.com/p/weed-fs/weed/util"
  9. )
  10. type Location struct {
  11. Url string "url"
  12. PublicUrl string "publicUrl"
  13. }
  14. type LookupResult struct {
  15. Locations []Location "locations"
  16. Error string "error"
  17. }
  18. //TODO: Add a caching for vid here
  19. func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
  20. values := make(url.Values)
  21. values.Add("volumeId", vid.String())
  22. jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
  23. if err != nil {
  24. return nil, err
  25. }
  26. var ret LookupResult
  27. err = json.Unmarshal(jsonBlob, &ret)
  28. if err != nil {
  29. return nil, err
  30. }
  31. if ret.Error != "" {
  32. return nil, errors.New(ret.Error)
  33. }
  34. return &ret, nil
  35. }