aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src
diff options
context:
space:
mode:
authorchris.lu@gmail.com <chris.lu@gmail.com@282b0af5-e82d-9cf1-ede4-77906d7719d0>2012-08-07 08:31:22 +0000
committerchris.lu@gmail.com <chris.lu@gmail.com@282b0af5-e82d-9cf1-ede4-77906d7719d0>2012-08-07 08:31:22 +0000
commit85da309eed6977eadf9b974780d5f119a76e0b9d (patch)
tree56cb8c02c2bd42e47fab972e1c5466b0671b15d7 /weed-fs/src
parent5e9dc0e66829805f1084fef7f19ca95dba9baae6 (diff)
downloadseaweedfs-85da309eed6977eadf9b974780d5f119a76e0b9d.tar.xz
seaweedfs-85da309eed6977eadf9b974780d5f119a76e0b9d.zip
all switching to "weed command [args]" usage mode
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@65 282b0af5-e82d-9cf1-ede4-77906d7719d0
Diffstat (limited to 'weed-fs/src')
-rw-r--r--weed-fs/src/cmd/weedclient/weedclient.go117
1 files changed, 0 insertions, 117 deletions
diff --git a/weed-fs/src/cmd/weedclient/weedclient.go b/weed-fs/src/cmd/weedclient/weedclient.go
deleted file mode 100644
index b6b93e41e..000000000
--- a/weed-fs/src/cmd/weedclient/weedclient.go
+++ /dev/null
@@ -1,117 +0,0 @@
-package main
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "flag"
- "fmt"
- "io"
- "io/ioutil"
- "mime/multipart"
- "net/http"
- "net/url"
- "os"
- "pkg/util"
- "strconv"
-)
-
-var (
- server = flag.String("server", "localhost:9333", "weedfs master location")
- IsDebug = flag.Bool("debug", false, "verbose debug information")
-)
-
-type AssignResult struct {
- Fid string "fid"
- Url string "url"
- PublicUrl string "publicUrl"
- Count int `json:",string"`
- Error string "error"
-}
-
-func assign(count int) (AssignResult, error) {
- values := make(url.Values)
- values.Add("count", strconv.Itoa(count))
- jsonBlob := util.Post("http://"+*server+"/dir/assign", values)
- var ret AssignResult
- err := json.Unmarshal(jsonBlob, &ret)
- if err != nil {
- return ret, err
- }
- if ret.Count <= 0 {
- return ret, errors.New(ret.Error)
- }
- return ret, nil
-}
-
-type UploadResult struct {
- Size int
-}
-
-func upload(filename string, uploadUrl string) (int, string) {
- body_buf := bytes.NewBufferString("")
- body_writer := multipart.NewWriter(body_buf)
- file_writer, err := body_writer.CreateFormFile("file", filename)
- if err != nil {
- panic(err.Error())
- }
- fh, err := os.Open(filename)
- if err != nil {
- panic(err.Error())
- }
- io.Copy(file_writer, fh)
- content_type := body_writer.FormDataContentType()
- body_writer.Close()
- resp, err := http.Post(uploadUrl, content_type, body_buf)
- if err != nil {
- panic(err.Error())
- }
- defer resp.Body.Close()
- resp_body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- panic(err.Error())
- }
- var ret UploadResult
- err = json.Unmarshal(resp_body, &ret)
- if err != nil {
- panic(err.Error())
- }
- //fmt.Println("Uploaded " + strconv.Itoa(ret.Size) + " Bytes to " + uploadUrl)
- return ret.Size, uploadUrl
-}
-
-type SubmitResult struct {
- Fid string "fid"
- Size int "size"
-}
-
-func submit(files []string)([]SubmitResult) {
- ret, err := assign(len(files))
- if err != nil {
- panic(err)
- }
- results := make([]SubmitResult, len(files))
- for index, file := range files {
- fid := ret.Fid
- if index > 0 {
- fid = fid + "_" + strconv.Itoa(index)
- }
- uploadUrl := "http://" + ret.PublicUrl + "/" + fid
- results[index].Size, _ = upload(file, uploadUrl)
- results[index].Fid = fid
- }
- return results
-}
-
-func main() {
- flag.Parse()
- if len(flag.Args()) == 0 {
- fmt.Fprintln(os.Stderr, "Submit one file or multiple version of the same file.")
- fmt.Fprintf(os.Stderr, "Usage: %s -server=<host>:<port> file1 [file2 file3 ...]\n", os.Args[0])
- flag.Usage()
- return
- }
- results := submit(flag.Args())
- bytes, _ := json.Marshal(results)
- fmt.Print(string(bytes))
-}