gdriver

package module
v0.0.0-...-65e2c62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2019 License: MIT Imports: 9 Imported by: 2

README

GDriver

A golang implementation to access google drive by using traditional file-folder-path pattern.

    f, _ := os.Open("image1.jpeg")
    gdrive.PutFile("Holidays/image1.jpeg", f)
    gdrive.Delete("Pictures/Old Apartment Images")

Example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackError

type CallbackError struct {
	NestedError error
}

CallbackError will be returned if the callback returned an error

func (CallbackError) Error

func (e CallbackError) Error() string

type FileInfo

type FileInfo struct {
	// contains filtered or unexported fields
}

FileInfo represents file information for a file or directory

func (*FileInfo) CreationTime

func (i *FileInfo) CreationTime() time.Time

CreationTime returns the time when this file was created

func (*FileInfo) DriveFile

func (i *FileInfo) DriveFile() *drive.File

DriveFile returns the underlaying drive.File

func (*FileInfo) IsDir

func (i *FileInfo) IsDir() bool

IsDir returns true if this file is a directory

func (*FileInfo) ModifiedTime

func (i *FileInfo) ModifiedTime() time.Time

ModifiedTime returns the time when this file was modified

func (*FileInfo) Name

func (i *FileInfo) Name() string

Name returns the name of the file or directory

func (*FileInfo) ParentPath

func (i *FileInfo) ParentPath() string

ParentPath returns the parent path of the file or directory

func (*FileInfo) Path

func (i *FileInfo) Path() string

Path returns the full path to this file or directory

func (*FileInfo) Size

func (i *FileInfo) Size() int64

Size returns the bytes for this file

type GDriver

type GDriver struct {
	// contains filtered or unexported fields
}

func New

func New(client *http.Client) (*GDriver, error)

New creates a new Google Drive Driver, client must me an authenticated instance for google drive

func (*GDriver) Delete

func (d *GDriver) Delete(path string) error

Delete will delete a file or directory, if directory it will also delete its descendants

func (*GDriver) DeleteDirectory

func (d *GDriver) DeleteDirectory(path string) error

DeleteDirectory will delete a directory and its descendants

func (*GDriver) GetFile

func (d *GDriver) GetFile(path string) (*FileInfo, io.ReadCloser, error)

GetFile gets a file and returns a ReadCloser that can consume the body of the file

func (*GDriver) GetFileById

func (d *GDriver) GetFileById(id string) (io.ReadCloser, error)

GetFileById gets a file and returns a ReadCloser that can consume the body of the file

func (*GDriver) GetFileHash

func (d *GDriver) GetFileHash(path string, method HashMethod) (*FileInfo, []byte, error)

GetFileHash returns the hash of a file with the present method

func (*GDriver) ListDirectory

func (d *GDriver) ListDirectory(path string, fileFunc func(*FileInfo) error) error

ListDirectory will get all contents of a directory, calling fileFunc with the collected file information

func (*GDriver) ListTrash

func (d *GDriver) ListTrash(filePath string, fileFunc func(f *FileInfo) error) error

ListTrash lists the contents of the trash, if you specify directories it will only list the trash contents of the specified directories

func (*GDriver) MakeDirectory

func (d *GDriver) MakeDirectory(path string) (*FileInfo, error)

MakeDirectory creates a directory for the specified path, it will create non existent directores automatically

Examples:

MakeDirectory("Pictures/Holidays") // will create Pictures and Holidays

func (*GDriver) Move

func (d *GDriver) Move(oldPath, newPath string) (*FileInfo, error)

Move moves a file or directory to a new path, note that move also renames the target if necessary and creates non existing directories

Examples:

Move("Folder1/File1", "Folder2/File2") // File1 in Folder1 will be moved to Folder2/File2
Move("Folder1/File1", "Folder2/File1") // File1 in Folder1 will be moved to Folder2/File1

func (*GDriver) PutFile

func (d *GDriver) PutFile(filePath string, appProperties map[string]string, r io.Reader) (*FileInfo, error)

PutFile uploads a file to the specified path it creates non existing directories

func (*GDriver) Rename

func (d *GDriver) Rename(path string, newName string) (*FileInfo, error)

Rename renames a file or directory to a new name in the same folder

func (*GDriver) SetRootDirectory

func (d *GDriver) SetRootDirectory(path string) (*FileInfo, error)

SetRootDirectory changes the working root directory use this if you want to do certian operations in a special directory path should always be the absolute real path

func (*GDriver) Stat

func (d *GDriver) Stat(path string) (*FileInfo, error)

Stat gives a FileInfo for a file or directory

func (*GDriver) Trash

func (d *GDriver) Trash(path string) error

Trash trashes a file or directory

type HashMethod

type HashMethod int
const (
	HashMethodMD5 HashMethod = 0
)

type NotFoundError

type NotFoundError struct {
	Path string
}

NotFoundError will be thown if an file was not found

func (NotFoundError) Error

func (e NotFoundError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL