diff options
| author | Petter Rasmussen | 2016-02-21 21:03:26 +0100 |
|---|---|---|
| committer | Petter Rasmussen | 2016-02-21 21:03:26 +0100 |
| commit | 1973512dd8edca24df4124fb3dfac4a432a0d481 (patch) | |
| tree | c61daefa5cf24eb2211ac816862697f9e0676d86 /drive/import.go | |
| parent | 701c7f1991ae765a51b0b7404d1edbb2dc523055 (diff) | |
| download | gdrive-1973512dd8edca24df4124fb3dfac4a432a0d481.tar.bz2 | |
go fmt
Diffstat (limited to 'drive/import.go')
| -rw-r--r-- | drive/import.go | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/drive/import.go b/drive/import.go index a3d8b3b..2ee5f1e 100644 --- a/drive/import.go +++ b/drive/import.go @@ -1,53 +1,53 @@ package drive import ( - "io" - "io/ioutil" - "fmt" - "strings" - "mime" - "path/filepath" + "fmt" + "io" + "io/ioutil" + "mime" + "path/filepath" + "strings" ) type ImportArgs struct { - Out io.Writer - Progress io.Writer - Path string - Parents []string + Out io.Writer + Progress io.Writer + Path string + Parents []string } func (self *Drive) Import(args ImportArgs) error { - fromMime := getMimeType(args.Path) - if fromMime == "" { - return fmt.Errorf("Could not determine mime type of file") - } - - about, err := self.service.About.Get().Fields("importFormats").Do() - if err != nil { - return fmt.Errorf("Failed to get about: %s", err) - } - - toMimes, ok := about.ImportFormats[fromMime] - if !ok || len(toMimes) == 0 { - return fmt.Errorf("Mime type '%s' is not supported for import", fromMime) - } - - f, _, err := self.uploadFile(UploadArgs{ - Out: ioutil.Discard, - Progress: args.Progress, - Path: args.Path, - Parents: args.Parents, - Mime: toMimes[0], - }) - if err != nil { - return err - } - - fmt.Fprintf(args.Out, "Imported %s with mime type: '%s'\n", f.Id, toMimes[0]) - return nil + fromMime := getMimeType(args.Path) + if fromMime == "" { + return fmt.Errorf("Could not determine mime type of file") + } + + about, err := self.service.About.Get().Fields("importFormats").Do() + if err != nil { + return fmt.Errorf("Failed to get about: %s", err) + } + + toMimes, ok := about.ImportFormats[fromMime] + if !ok || len(toMimes) == 0 { + return fmt.Errorf("Mime type '%s' is not supported for import", fromMime) + } + + f, _, err := self.uploadFile(UploadArgs{ + Out: ioutil.Discard, + Progress: args.Progress, + Path: args.Path, + Parents: args.Parents, + Mime: toMimes[0], + }) + if err != nil { + return err + } + + fmt.Fprintf(args.Out, "Imported %s with mime type: '%s'\n", f.Id, toMimes[0]) + return nil } func getMimeType(path string) string { - t := mime.TypeByExtension(filepath.Ext(path)) - return strings.Split(t, ";")[0] + t := mime.TypeByExtension(filepath.Ext(path)) + return strings.Split(t, ";")[0] } |
