Compare commits

..

No commits in common. "master" and "v0.0.5" have entirely different histories.

2 changed files with 8 additions and 10 deletions

View File

@ -1,4 +1,2 @@
# download

View File

@ -86,7 +86,7 @@ func (g GoogleDrive) GetFilesByFolderID(folderID string, mimeType []string) ([]G
}
// DownloadByFileID download file into specific path
func (g GoogleDrive) DownloadByFileID(id, path string) (filename string, err error) {
func (g GoogleDrive) DownloadByFileID(id, path string) (err error) {
// trim "/" in the end of path
path = strings.TrimSuffix(path, "/")
@ -96,21 +96,21 @@ func (g GoogleDrive) DownloadByFileID(id, path string) (filename string, err err
// Get the data
resp, err := http.Get(url)
if err != nil {
return "", err
return err
}
defer resp.Body.Close()
// Check server response
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("bad status: %s", resp.Status)
return fmt.Errorf("bad status: %s", resp.Status)
}
// get file name
filename = getFileNameFromHeaderContentDisposition(resp.Header.Get("Content-Disposition"))
filename := getFileNameFromHeaderContentDisposition(resp.Header.Get("Content-Disposition"))
// return err if not found
if filename == "" {
return "", errors.New("file is not existed or is in private mode, please check again")
return errors.New("file is not existed or is in private mode, please check again")
}
// assign location with field name
@ -119,7 +119,7 @@ func (g GoogleDrive) DownloadByFileID(id, path string) (filename string, err err
// Create the file
out, err := os.Create(location)
if err != nil {
return "", err
return err
}
defer out.Close()
@ -129,8 +129,8 @@ func (g GoogleDrive) DownloadByFileID(id, path string) (filename string, err err
// Writer the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
return "", err
return err
}
return filename, nil
return nil
}