Documentation ¶
Index ¶
- Constants
- Variables
- type File
- type Service
- func (s *Service) Download(file *drive.File, path string) error
- func (s *Service) DownloadFile(f *drive.File, path string) (downloaded bool, err error)
- func (s *Service) DownloadTree(root *File, outpath string, downloaders int) error
- func (s *Service) Export(file *drive.File, mimeType, path string) error
- func (s *Service) List() ([]*drive.File, error)
- func (s *Service) Root() (string, error)
Constants ¶
const ErrReasonRateLimitExceeded = "rateLimitExceeded"
const ErrReasonSizeLimitExceeded = "exportSizeLimitExceeded"
const FileTypeFolder = "application/vnd.google-apps.folder"
const FileTypeSDKPrefix = "application/vnd.google-apps.drive-sdk."
const FileTypeShortcut = "application/vnd.google-apps.shortcut"
Variables ¶
var ErrNoExportableFormat = errors.New("no exportable format")
var ExportExtensions = map[string]string{
"application/vnd.google-apps.document": ".docx",
"application/vnd.google-apps.presentation": ".pptx",
"application/vnd.google-apps.spreadsheet": ".xlsx",
"application/vnd.google-apps.drawing": ".svg",
"application/vnd.google-apps.jam": ".pdf",
"application/vnd.google-apps.script": ".json",
"application/vnd.google-apps.form": ".zip",
"application/vnd.google-apps.site": ".txt",
}
var ExportTypes = map[string]string{
"application/vnd.google-apps.document": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.google-apps.presentation": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.google-apps.spreadsheet": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.google-apps.drawing": "image/svg+xml",
"application/vnd.google-apps.jam": "application/pdf",
"application/vnd.google-apps.script": "application/vnd.google-apps.script+json",
"application/vnd.google-apps.form": "application/zip",
"application/vnd.google-apps.site": "text/plain",
}
var SkipTypes = map[string]struct{}{
"application/vnd.google-apps.fusiontable": {},
"application/vnd.google-apps.map": {},
}
var ValidPathChars = regexp.MustCompile("[^a-zA-Z0-9 !@#$%^&()\\-_=+\\[\\]{}';\\.,`~]")
ValidPathChars is the set of valid path name characters
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { ID string Name string File *drive.File Files []*File Parents []*File ShortcutTarget *File }
File represents a Google Drive File or Folder. A Google Drive object can have multiple parents
func NewTree ¶
NewTree parses a list of Google Drive files and returns two trees: a tree rooted at the user's Google Drive (specified by rootID) and an "Other Files" tree which includes all files not under the main tree.
type Service ¶
type Service struct { *drive.FilesService // contains filtered or unexported fields }
Service is a Google Drive file service
func NewService ¶
NewService returns a new service using the service account credentials JSON file found at configPath for the given user initialBackoff and tries are used to configure an exponential backoff strategy. Set tries to 1 to disable retries or set tries to <= 0 to retry infinitely
To create the JSON file for configPath:
- Create or open a project at https://console.cloud.google.com
- Create a new service account at IAM & Admin -> Service Accounts
- Add a new key to the service account (as JSON)
- Add the client_id found in the JSON file to [Domain-wide Delegation](https://admin.google.com/ac/owl/domainwidedelegation)
- Add the https://www.googleapis.com/auth/drive and https://www.googleapis.com/auth/drive.metadata scopes
func (*Service) Download ¶
Download downloads the file with id to path. Most users should use DownloadFile instead
func (*Service) DownloadFile ¶
DownloadFile downloads f to path. It automatically resolves shortcuts and converts Google Docs, Slides, Sheets, and Drawings to downloadable formats. If downloaded is false, the file was not downloaded because the existing file matched.
func (*Service) DownloadTree ¶
DownloadTree downloads the file tree rooted at root to outpath using the specified number of downloaders. If downloaders is less than 1, runtime.NumCPU() will be used
func (*Service) Export ¶
Export exports (with specified mime type) the file with id to path. Most users should use DownloadFile instead