"Fossies" - the Fresh Open Source Software Archive 
Member "gdrive-2.1.1/drive/mkdir.go" (28 May 2021, 846 Bytes) of package /linux/misc/gdrive-2.1.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 package drive
2
3 import (
4 "fmt"
5 "google.golang.org/api/drive/v3"
6 "io"
7 )
8
9 const DirectoryMimeType = "application/vnd.google-apps.folder"
10
11 type MkdirArgs struct {
12 Out io.Writer
13 Name string
14 Description string
15 Parents []string
16 }
17
18 func (self *Drive) Mkdir(args MkdirArgs) error {
19 f, err := self.mkdir(args)
20 if err != nil {
21 return err
22 }
23 fmt.Fprintf(args.Out, "Directory %s created\n", f.Id)
24 return nil
25 }
26
27 func (self *Drive) mkdir(args MkdirArgs) (*drive.File, error) {
28 dstFile := &drive.File{
29 Name: args.Name,
30 Description: args.Description,
31 MimeType: DirectoryMimeType,
32 }
33
34 // Set parent folders
35 dstFile.Parents = args.Parents
36
37 // Create directory
38 f, err := self.service.Files.Create(dstFile).Do()
39 if err != nil {
40 return nil, fmt.Errorf("Failed to create directory: %s", err)
41 }
42
43 return f, nil
44 }