forked from prasmussen/gdrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkdir.go
46 lines (36 loc) · 968 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
46
package drive
import (
"google.golang.org/api/drive/v3"
"io"
"fmt"
)
const DirectoryMimeType = "application/vnd.google-apps.folder"
type MkdirArgs struct {
Out io.Writer
Name string
Parents []string
Share bool
}
func (self *Drive) Mkdir(args MkdirArgs) error {
f, err := self.mkdir(args)
if err != nil {
return err
}
fmt.Printf("Directory '%s' created\n", f.Name)
return nil
}
func (self *Drive) mkdir(args MkdirArgs) (*drive.File, error) {
dstFile := &drive.File{Name: args.Name, MimeType: DirectoryMimeType}
// Set parent folders
dstFile.Parents = args.Parents
// Create directory
f, err := self.service.Files.Create(dstFile).Do()
if err != nil {
return nil, fmt.Errorf("Failed to create directory: %s", err)
}
fmt.Fprintf(args.Out, "\n[directory] id: %s, name: %s\n", f.Id, f.Name)
//if args.Share {
// self.share(TODO)
//}
return f, nil
}