add lots of error checking by GThomas

This commit is contained in:
Chris Lu
2013-02-26 22:54:22 -08:00
parent bd278337db
commit db8e27be6e
29 changed files with 268 additions and 170 deletions

View File

@@ -1,12 +1,12 @@
package operation
import (
"encoding/json"
"errors"
"net/url"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/topology"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
"errors"
"net/url"
)
type AllocateVolumeResult struct {

View File

@@ -1,12 +1,12 @@
package operation
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
"errors"
_ "fmt"
"net/url"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
)
type Location struct {

View File

@@ -21,9 +21,19 @@ func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult,
body_buf := bytes.NewBufferString("")
body_writer := multipart.NewWriter(body_buf)
file_writer, err := body_writer.CreateFormFile("file", filename)
io.Copy(file_writer, reader)
if err != nil {
log.Println("error creating form file", err)
return nil, err
}
if _, err = io.Copy(file_writer, reader); err != nil {
log.Println("error copying data", err)
return nil, err
}
content_type := body_writer.FormDataContentType()
body_writer.Close()
if err = body_writer.Close(); err != nil {
log.Println("error closing body", err)
return nil, err
}
resp, err := http.Post(uploadUrl, content_type, body_buf)
if err != nil {
log.Println("failing to upload to", uploadUrl)