forked from prasmussen/gdrive
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mkdir.go
45 lines (36 loc) · 872 Bytes
/
mkdir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package drive
import (
"fmt"
"io"
"google.golang.org/api/drive/v3"
)
const DirectoryMimeType = "application/vnd.google-apps.folder"
type MkdirArgs struct {
Out io.Writer
Name string
Description string
Parents []string
}
func (self *Drive) Mkdir(args MkdirArgs) error {
f, err := self.mkdir(args)
if err != nil {
return err
}
fmt.Fprintf(args.Out, "Directory %s created\n", f.Id)
return nil
}
func (self *Drive) mkdir(args MkdirArgs) (*drive.File, error) {
dstFile := &drive.File{
Name: args.Name,
Description: args.Description,
MimeType: DirectoryMimeType,
}
// Set parent folders
dstFile.Parents = args.Parents
// Create directory
f, err := self.service.Files.Create(dstFile).SupportsTeamDrives(true).Do()
if err != nil {
return nil, fmt.Errorf("Failed to create directory: %s", err)
}
return f, nil
}