Documentation
¶
Index ¶
- func CreateDate(driveFile *drive.File) (time.Time, error)
- func IsDir(driveFile *drive.File) bool
- func IsObjectNotFound(e error) bool
- func ModifiedDate(driveFile *drive.File) (time.Time, error)
- type Error
- type Gdrive
- func (g *Gdrive) Download(srcPath string) (io.Reader, error)
- func (g *Gdrive) DownloadToFile(srcPath string, localFile string) (int64, error)
- func (g *Gdrive) GdriveChildrenList(parentID string, query string) ([]*drive.ChildReference, error)
- func (g *Gdrive) GdriveFilesGet(fileID string) (*drive.File, error)
- func (g *Gdrive) GdriveFilesInsert(reader io.Reader, title string, parentID string, mimeType string) (*drive.File, error)
- func (g *Gdrive) GdriveFilesPatch(fileID string, title string, modifiedDate string, addParentIds []string, ...) (*drive.File, error)
- func (g *Gdrive) GdriveFilesTrash(fileID string) (*drive.File, error)
- func (g *Gdrive) Insert(dstPath string, reader io.Reader) (*drive.File, error)
- func (g *Gdrive) InsertInPlace(dstPath string, reader io.Reader) (*drive.File, error)
- func (g *Gdrive) ListDir(drivePath string, query string) ([]*drive.File, error)
- func (g *Gdrive) Mkdir(drivePath string) (*drive.File, error)
- func (g *Gdrive) Move(srcPath string, dstPath string) (*drive.File, error)
- func (g *Gdrive) SetDebugLevel(n int)
- func (g *Gdrive) SetModifiedDate(drivePath string, modifiedDate time.Time) (*drive.File, error)
- func (g *Gdrive) SetVerboseLevel(n int)
- func (g *Gdrive) Stat(drivePath string) (*drive.File, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDate ¶
CreateDate returns the time.Time representation of the *drive.File object's creation date.
func IsObjectNotFound ¶
IsObjectNotFound Returns true if the passed error is of type godrive.Error and the error condition was caused by an Object Not Found.
Types ¶
type Error ¶
type Error struct {
ObjectNotFound bool
// contains filtered or unexported fields
}
Error defines a custom error for godrive
type Gdrive ¶
type Gdrive struct {
// contains filtered or unexported fields
}
Gdrive is the main structure representing a GoDrive object
func NewGoDrive ¶
func NewGoDrive(clientID string, clientSecret string, code string, scope string, cacheFile string) (*Gdrive, error)
NewGoDrive creates and returns a new *Gdrive Object or (nil, error) in case of problems.
func (*Gdrive) Download ¶
Download a file from Gdrive. Returns an io.Reader to gdrive file pointed by srcPath. The io.Reader can be used to save the file locally by the caller.
func (*Gdrive) DownloadToFile ¶
DownloadToFile downloads a file named 'srcPath' into 'localFile'. localFile will be overwritten if it exists. The file is first downloaded into a temporary file and then atomically moved into the destination file. Returns the number of bytes downloaded.
func (*Gdrive) GdriveChildrenList ¶
GdriveChildrenList returns a slice of *drive.ChilReference containing all objects under 'ParentId' which satisfy the 'query' parameter.
func (*Gdrive) GdriveFilesGet ¶
GdriveFilesGet returns a *drive.File object for the object identified by 'fileId'
func (*Gdrive) GdriveFilesInsert ¶
func (g *Gdrive) GdriveFilesInsert(reader io.Reader, title string, parentID string, mimeType string) (*drive.File, error)
GdriveFilesInsert inserts a new Object (file/dir) on Google Drive under 'parentId'. The object's contents will come from 'reader' (io.Reader). If reader is nil, an empty object will be created (this is how we create directories). The title of the object will be set to 'title' and the object's MIME Type will be set to 'mimeType', or automatically detected if mimeType is blank.
Returns a *drive.File object pointing to the file just inserted.
func (*Gdrive) GdriveFilesPatch ¶
func (g *Gdrive) GdriveFilesPatch(fileID string, title string, modifiedDate string, addParentIds []string, removeParentIds []string) (*drive.File, error)
GdriveFilesPatch patches a Gdrive object metadata. Currently it can change the Title, modifiedDate, and the list of parent Ids. Setting values to a blank string (when of type string) or an empty slice (type slice) will cause that particular attribute to remain untouched.
Returns a *drive.File object pointing to the modified file.
func (*Gdrive) GdriveFilesTrash ¶
GdriveFilesTrash moves the object indicated by 'fileID' to the Google Drive Trash. Returns a *drive.File object pointing to the file inside Trash.
func (*Gdrive) Insert ¶
Insert inserts a file named 'dstPath' with the contents coming from 'reader'. The method calls the 'insert' method with the inplace option set to false, causing the file to be writen to a temporary location and then renamed to its final place. This method is safer (but slower) than the InsertInPlace method.
Returns *drive.File pointing to the file in its final location.
func (*Gdrive) InsertInPlace ¶
InsertInPlace inserts a file named 'dstPath' with the contents coming from reader. The method calls the 'insert' method with the inplace option set to true, causing the file to be written directly to its final destination. This is faster but (theoretically) less safe than using "Insert".
Returns *drive.File: pointing to the file in its final location.
func (*Gdrive) ListDir ¶
ListDir returns a slice of *drive.File objects under 'drivePath' matching 'query' (in Google Drive query format.) If query is blank, it defaults to 'trashed = false'.
func (*Gdrive) Mkdir ¶
Mkdir creates the directory (folder) specified by drivePath. Returns the *drive.File pointing to the object. If the folder already exists, the *drive.File of the existing folder will be returned (this saves one Stat when creating directories.)
func (*Gdrive) Move ¶
Move renames/moves the object in 'srcPath' (file or directory) to 'dstPath' by calling patch to replace dstPath as the parent of 'srcPath'. The paths are full paths (dir/dir/dir.../file). Returns the *drive.File containing the destination object.
func (*Gdrive) SetDebugLevel ¶
SetDebugLevel sets the debug level for future uses of the log.Debug{ln,f} methods.
func (*Gdrive) SetModifiedDate ¶
SetModifiedDate sets the modification date of the file/directory specified by 'drivePath' to 'modifiedDate'. Returns *drive.File pointing to the modified file/dir.
func (*Gdrive) SetVerboseLevel ¶
SetVerboseLevel sets the verbose level for future uses of the log.Verbose{ln,f} methods.
func (*Gdrive) Stat ¶
Stat returns the *drive.File object for the last element in 'drivePath'. The path must be specified as a full path (similar to unix filesystem path.)
Google Drive allows more than one object with the same name and Unix filesystems do not. Stat returns an error if a duplicate is found anywhere in the requested path (which will require human intervention, and should never happen if only this set of routines is used to create files under that path.) Stat returns an instance of godrive.Error with ObjectNotFound set if the requested object cannot be found. Use g.IsObjecNotFound(err) to test for this condition.
Returns *drive.File object of the object pointed by the full path.