mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-11 07:49:08 +08:00
b9aee2defb
The volume TTL and file TTL are not necessarily the same. as long as file TTL is smaller than volume TTL, it'll be fine. volume TTL is used when assigning file id, e.g. http://.../dir/assign?ttl=3h file TTL is used when uploading
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
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,omitempty"`
|
|
Url string `json:"url,omitempty"`
|
|
PublicUrl string `json:"publicUrl,omitempty"`
|
|
Count int `json:"count,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
func Assign(server string, count int, replication string, collection string, ttl string) (*AssignResult, error) {
|
|
values := make(url.Values)
|
|
values.Add("count", strconv.Itoa(count))
|
|
if replication != "" {
|
|
values.Add("replication", replication)
|
|
}
|
|
if collection != "" {
|
|
values.Add("collection", collection)
|
|
}
|
|
if ttl != "" {
|
|
values.Add("ttl", ttl)
|
|
}
|
|
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
|
|
}
|