diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-08-14 11:31:39 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-08-14 11:31:39 -0700 |
| commit | 37b231b5dc76e90d02aca9fe471dc7371e902ac2 (patch) | |
| tree | 9810866a1aae4613513f33175cc927df26e821a7 | |
| parent | 8e1ac16d1625612e8c33eb2e736efcebbdab32e9 (diff) | |
| download | seaweedfs-37b231b5dc76e90d02aca9fe471dc7371e902ac2.tar.xz seaweedfs-37b231b5dc76e90d02aca9fe471dc7371e902ac2.zip | |
Only limit input parameter to io.Reader
| -rw-r--r-- | go/operation/submit.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/go/operation/submit.go b/go/operation/submit.go index b157fc052..e0001e60b 100644 --- a/go/operation/submit.go +++ b/go/operation/submit.go @@ -11,11 +11,11 @@ import ( ) type FilePart struct { - ReadCloser io.ReadCloser //required, all rest are optional - FileName string - IsGzipped bool - MimeType string - ModTime int64 //in seconds + Reader io.Reader //required, all rest are optional + FileName string + IsGzipped bool + MimeType string + ModTime int64 //in seconds } type SubmitResult struct { @@ -69,7 +69,7 @@ func NewFilePart(fullPathFilename string) (ret FilePart, err error) { glog.V(0).Info("Failed to open file: ", fullPathFilename) return ret, openErr } - ret.ReadCloser = fh + ret.Reader = fh if fi, fiErr := fh.Stat(); fiErr != nil { glog.V(0).Info("Failed to stat file:", fullPathFilename) @@ -95,8 +95,10 @@ func (fi FilePart) Upload(server string, fid string) (int, error) { if fi.ModTime != 0 { fileUrl += "?ts=" + strconv.Itoa(int(fi.ModTime)) } - defer fi.ReadCloser.Close() - ret, e := Upload(fileUrl, fi.FileName, fi.ReadCloser, fi.IsGzipped, fi.MimeType) + if closer, ok := fi.Reader.(io.Closer); ok{ + defer closer.Close() + } + ret, e := Upload(fileUrl, fi.FileName, fi.Reader, fi.IsGzipped, fi.MimeType) if e != nil { return 0, e } |
