"Fossies" - the Fresh Open Source Software Archive 
Member "gdrive-2.1.1/drive/info.go" (28 May 2021, 1537 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 type FileInfoArgs struct {
10 Out io.Writer
11 Id string
12 SizeInBytes bool
13 }
14
15 func (self *Drive) Info(args FileInfoArgs) error {
16 f, err := self.service.Files.Get(args.Id).Fields("id", "name", "size", "createdTime", "modifiedTime", "md5Checksum", "mimeType", "parents", "shared", "description", "webContentLink", "webViewLink").Do()
17 if err != nil {
18 return fmt.Errorf("Failed to get file: %s", err)
19 }
20
21 pathfinder := self.newPathfinder()
22 absPath, err := pathfinder.absPath(f)
23 if err != nil {
24 return err
25 }
26
27 PrintFileInfo(PrintFileInfoArgs{
28 Out: args.Out,
29 File: f,
30 Path: absPath,
31 SizeInBytes: args.SizeInBytes,
32 })
33
34 return nil
35 }
36
37 type PrintFileInfoArgs struct {
38 Out io.Writer
39 File *drive.File
40 Path string
41 SizeInBytes bool
42 }
43
44 func PrintFileInfo(args PrintFileInfoArgs) {
45 f := args.File
46
47 items := []kv{
48 kv{"Id", f.Id},
49 kv{"Name", f.Name},
50 kv{"Path", args.Path},
51 kv{"Description", f.Description},
52 kv{"Mime", f.MimeType},
53 kv{"Size", formatSize(f.Size, args.SizeInBytes)},
54 kv{"Created", formatDatetime(f.CreatedTime)},
55 kv{"Modified", formatDatetime(f.ModifiedTime)},
56 kv{"Md5sum", f.Md5Checksum},
57 kv{"Shared", formatBool(f.Shared)},
58 kv{"Parents", formatList(f.Parents)},
59 kv{"ViewUrl", f.WebViewLink},
60 kv{"DownloadUrl", f.WebContentLink},
61 }
62
63 for _, item := range items {
64 if item.value != "" {
65 fmt.Fprintf(args.Out, "%s: %s\n", item.key, item.value)
66 }
67 }
68 }