diff options
| author | chrislusf <chris.lu@gmail.com> | 2015-05-26 00:58:41 -0700 |
|---|---|---|
| committer | chrislusf <chris.lu@gmail.com> | 2015-05-26 00:58:41 -0700 |
| commit | 86cd40fba87f7e69c10d1e66e967f6e5e40605b6 (patch) | |
| tree | 0bec704ff7aa8c0dd89c2f4852844a230e46c821 /go/util | |
| parent | 7272af8ec45426151593fcd7d1a4d5a8092d5de6 (diff) | |
| download | seaweedfs-86cd40fba87f7e69c10d1e66e967f6e5e40605b6.tar.xz seaweedfs-86cd40fba87f7e69c10d1e66e967f6e5e40605b6.zip | |
Add "weed backup" command.
This is a pre-cursor for asynchronous replication.
Diffstat (limited to 'go/util')
| -rw-r--r-- | go/util/http_util.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/go/util/http_util.go b/go/util/http_util.go index 10e781140..7854302ab 100644 --- a/go/util/http_util.go +++ b/go/util/http_util.go @@ -3,6 +3,7 @@ package util import ( "bytes" "fmt" + "io" "io/ioutil" "net/http" "net/url" @@ -84,6 +85,43 @@ func Delete(url string, jwt security.EncodedJwt) error { return nil } +func GetBufferStream(url string, values url.Values, allocatedBytes []byte, eachBuffer func([]byte)) error { + r, err := client.PostForm(url, values) + if err != nil { + return err + } + defer r.Body.Close() + if r.StatusCode != 200 { + return fmt.Errorf("%s: %s", url, r.Status) + } + bufferSize := len(allocatedBytes) + for { + n, err := r.Body.Read(allocatedBytes) + if n == bufferSize { + eachBuffer(allocatedBytes) + } + if err != nil { + if err == io.EOF { + return nil + } + return err + } + } + return nil +} + +func GetUrlStream(url string, values url.Values, readFn func(io.Reader) error) error { + r, err := client.PostForm(url, values) + if err != nil { + return err + } + defer r.Body.Close() + if r.StatusCode != 200 { + return fmt.Errorf("%s: %s", url, r.Status) + } + return readFn(r.Body) +} + func DownloadUrl(fileUrl string) (filename string, content []byte, e error) { response, err := client.Get(fileUrl) if err != nil { |
