aboutsummaryrefslogtreecommitdiff
path: root/go/operation/assign_file_id.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-08-13 23:26:51 -0700
committerChris Lu <chris.lu@gmail.com>2013-08-13 23:26:51 -0700
commitd5e7c1de0ae4667d7362b869081eeeb6085a426b (patch)
tree843cdfc3be3245ec071c8fd8b556c13f89d21a69 /go/operation/assign_file_id.go
parentf7c1a15ad10dd48f4cd7042bded13cbe67bfb83d (diff)
downloadseaweedfs-d5e7c1de0ae4667d7362b869081eeeb6085a426b.tar.xz
seaweedfs-d5e7c1de0ae4667d7362b869081eeeb6085a426b.zip
refactoring code
reusable code by go clients
Diffstat (limited to 'go/operation/assign_file_id.go')
-rw-r--r--go/operation/assign_file_id.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/go/operation/assign_file_id.go b/go/operation/assign_file_id.go
new file mode 100644
index 000000000..a6680cbb8
--- /dev/null
+++ b/go/operation/assign_file_id.go
@@ -0,0 +1,40 @@
+package operation
+
+import (
+ "code.google.com/p/weed-fs/go/glog"
+ "code.google.com/p/weed-fs/go/util"
+ "encoding/json"
+ "errors"
+ "net/url"
+ "strconv"
+)
+
+type AssignResult struct {
+ Fid string `json:"fid"`
+ Url string `json:"url"`
+ PublicUrl string `json:"publicUrl"`
+ Count int
+ Error string `json:"error"`
+}
+
+func Assign(server string, count int, replication string) (*AssignResult, error) {
+ values := make(url.Values)
+ values.Add("count", strconv.Itoa(count))
+ if replication != "" {
+ values.Add("replication", replication)
+ }
+ jsonBlob, err := util.Post("http://"+server+"/dir/assign", values)
+ glog.V(2).Info("assign result :", string(jsonBlob))
+ if err != nil {
+ return nil, err
+ }
+ var ret AssignResult
+ err = json.Unmarshal(jsonBlob, &ret)
+ if err != nil {
+ return nil, err
+ }
+ if ret.Count <= 0 {
+ return nil, errors.New(ret.Error)
+ }
+ return &ret, nil
+}