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.

47 lines
1.1 KiB

  1. package operation
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "net/url"
  6. "strconv"
  7. "github.com/chrislusf/weed-fs/go/glog"
  8. "github.com/chrislusf/weed-fs/go/util"
  9. )
  10. type AssignResult struct {
  11. Fid string `json:"fid,omitempty"`
  12. Url string `json:"url,omitempty"`
  13. PublicUrl string `json:"publicUrl,omitempty"`
  14. Count int `json:"count,omitempty"`
  15. Error string `json:"error,omitempty"`
  16. }
  17. func Assign(server string, count int, replication string, collection string, ttl string) (*AssignResult, error) {
  18. values := make(url.Values)
  19. values.Add("count", strconv.Itoa(count))
  20. if replication != "" {
  21. values.Add("replication", replication)
  22. }
  23. if collection != "" {
  24. values.Add("collection", collection)
  25. }
  26. if ttl != "" {
  27. values.Add("ttl", ttl)
  28. }
  29. jsonBlob, err := util.Post("http://"+server+"/dir/assign", values)
  30. glog.V(2).Info("assign result :", string(jsonBlob))
  31. if err != nil {
  32. return nil, err
  33. }
  34. var ret AssignResult
  35. err = json.Unmarshal(jsonBlob, &ret)
  36. if err != nil {
  37. return nil, err
  38. }
  39. if ret.Count <= 0 {
  40. return nil, errors.New(ret.Error)
  41. }
  42. return &ret, nil
  43. }