diff options
| author | 霍晓栋 <huoxd@jiedaibao.com> | 2016-06-26 10:50:18 +0800 |
|---|---|---|
| committer | 霍晓栋 <huoxd@jiedaibao.com> | 2016-06-26 10:50:18 +0800 |
| commit | 1f630945422953429eff852a6b6a03b9c004e9ca (patch) | |
| tree | e966a0a726f77ab52c8c25c4bba4252368abb913 /weed/operation/assign_file_id.go | |
| parent | c601ef03b15d30e726ea86c070a2cb79035c37c9 (diff) | |
| download | seaweedfs-1f630945422953429eff852a6b6a03b9c004e9ca.tar.xz seaweedfs-1f630945422953429eff852a6b6a03b9c004e9ca.zip | |
refactor Volume Assign function
Diffstat (limited to 'weed/operation/assign_file_id.go')
| -rw-r--r-- | weed/operation/assign_file_id.go | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/weed/operation/assign_file_id.go b/weed/operation/assign_file_id.go index a893e836b..f2365890c 100644 --- a/weed/operation/assign_file_id.go +++ b/weed/operation/assign_file_id.go @@ -11,6 +11,16 @@ import ( "github.com/chrislusf/seaweedfs/weed/util" ) +type VolumeAssignRequest struct { + Count uint64 + Replication string + Collection string + Ttl string + DataCenter string + Rack string + DataNode string +} + type AssignResult struct { Fid string `json:"fid,omitempty"` Url string `json:"url,omitempty"` @@ -19,47 +29,26 @@ type AssignResult struct { Error string `json:"error,omitempty"` } -/* -options params meaning: -options[0] main data Center -options[1] main rack -options[2] main data node -*/ -func Assign(server string, count uint64, replication string, collection string, ttl string, options ...string) (*AssignResult, error) { +func Assign(server string, r *VolumeAssignRequest) (*AssignResult, error) { values := make(url.Values) - values.Add("count", strconv.FormatUint(count, 10)) - if replication != "" { - values.Add("replication", replication) + values.Add("count", strconv.FormatUint(r.Count, 10)) + if r.Replication != "" { + values.Add("replication", r.Replication) } - if collection != "" { - values.Add("collection", collection) + if r.Collection != "" { + values.Add("collection", r.Collection) } - if ttl != "" { - values.Add("ttl", ttl) + if r.Ttl != "" { + values.Add("ttl", r.Ttl) } - - var dataCenter, rack, dataNode string - switch len(options) { - case 1: - dataCenter = options[0] - case 2: - dataCenter = options[0] - rack = options[1] - case 3: - dataCenter = options[0] - rack = options[1] - dataNode = options[2] - default: - } - - if dataCenter != "" { - values.Add("dataCenter", dataCenter) + if r.DataCenter != "" { + values.Add("dataCenter", r.DataCenter) } - if rack != "" { - values.Add("rack", rack) + if r.Rack != "" { + values.Add("rack", r.Rack) } - if dataNode != "" { - values.Add("dataNode", dataNode) + if r.DataNode != "" { + values.Add("dataNode", r.DataNode) } jsonBlob, err := util.Post("http://"+server+"/dir/assign", values) |
