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.

58 lines
1.3 KiB

  1. package filer
  2. import ()
  3. import (
  4. "code.google.com/p/weed-fs/go/util"
  5. "encoding/json"
  6. "errors"
  7. _ "fmt"
  8. "net/url"
  9. "strconv"
  10. )
  11. type ListFilesResult struct {
  12. Files []FileEntry
  13. Error string `json:"error,omitempty"`
  14. }
  15. func ListFiles(server string, directoryId DirectoryId, fileName string) (*ListFilesResult, error) {
  16. values := make(url.Values)
  17. values.Add("directoryId", strconv.Itoa(int(directoryId)))
  18. jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
  19. if err != nil {
  20. return nil, err
  21. }
  22. var ret ListFilesResult
  23. err = json.Unmarshal(jsonBlob, &ret)
  24. if err != nil {
  25. return nil, err
  26. }
  27. if ret.Error != "" {
  28. return nil, errors.New(ret.Error)
  29. }
  30. return &ret, nil
  31. }
  32. type ListDirectoriesResult struct {
  33. Directories []DirectoryEntry
  34. Error string `json:"error,omitempty"`
  35. }
  36. func ListDirectories(server string, directoryId DirectoryId) (*ListDirectoriesResult, error) {
  37. values := make(url.Values)
  38. values.Add("directoryId", strconv.Itoa(int(directoryId)))
  39. jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
  40. if err != nil {
  41. return nil, err
  42. }
  43. var ret ListDirectoriesResult
  44. err = json.Unmarshal(jsonBlob, &ret)
  45. if err != nil {
  46. return nil, err
  47. }
  48. if ret.Error != "" {
  49. return nil, errors.New(ret.Error)
  50. }
  51. return &ret, nil
  52. }