gdrive

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gdrive is a package which provides utilities for manipulating (list, search, upload, download, delete) files on Google Drive. It has special handling for .csv files which it uploads as a Google Sheets documents (and downloads the first visible sheet of Google Sheets documents as .csv text) This can be more simple than using Google's API for common tasks; for anything more complicated use Google's golang sdk directly: https://pkg.go.dev/google.golang.org/api/drive/v3

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service wraps drive.FilesService

func NewServiceWithCtx

func NewServiceWithCtx(ctx context.Context) (*Service, error)

NewServiceWithCtx creates and wraps a new FilesService with the provided context

func (*Service) CreateFile

func (svc *Service) CreateFile(name, parent string, src io.Reader) (*drive.File, error)

CreateFile creats a new file named 'name' in folder with id 'parent' and content read from 'src'. If name has '.csv' extension, then the created file is converted to a Google Sheets document on the drive. If parent is empty, file will be created in user's drive root. If 'src' is nil, creates an empty file. (This will not overwrite any other files with the same name.) https://developers.google.com/drive/api/v3/create-file

func (*Service) CreateFolder

func (svc *Service) CreateFolder(name, parent string) (*drive.File, error)

CreateFolder creates a new empty directory named 'name' in folder with id 'parent'. If parent is empty, directory will be created in the authenticated user's drive root. (This will not overwrite any other files with the same name.) https://developers.google.com/drive/api/v3/folder

func (*Service) CreateOrUpdateFile

func (svc *Service) CreateOrUpdateFile(name, parent string,
	src io.Reader) (*drive.File, error)

CreateOrUpdateFile creates a new file named 'name' (with contents of 'src') if it does not already exist in 'parent'; otherwise it replaces the contents of the existing file.

func (*Service) DeleteFile

func (svc *Service) DeleteFile(id string) error

DeleteFile deletes file identified by 'id'

func (*Service) DownloadFile

func (svc *Service) DownloadFile(id string) (*http.Response, error)

DownloadFile returns a http.Response for downloading the contents of file identified by 'id'. If file is a Google Workspace file it is exported as a text format. https://developers.google.com/drive/api/v3/manage-downloads

func (*Service) FileContents

func (svc *Service) FileContents(id string) ([]byte, error)

FileContents downloads and returns the contents of the file identified by 'id'

func (*Service) FilesNamed

func (svc *Service) FilesNamed(name, parent string) ([]*drive.File, error)

FilesNamed returns a list of all files named 'name' in the 'parent' folder. If parent is empty, will return files from any files shared with user. If no matching file is found, returns empty list and nil error If an error is encountered it is returned along with any files that were found before encountering the error

func (*Service) FilesService

func (svc *Service) FilesService() *drive.FilesService

FilesService returns a pointer to the wrapped FilesService

func (*Service) GetInfo

func (svc *Service) GetInfo(id string) (*drive.File, error)

GetInfo returns all metadata for the file identified by 'id'

func (*Service) Search

func (svc *Service) Search(q string) ([]*drive.File, error)

Search searches all of the authenticated user's files. 'q' is the search query as documented here: https://developers.google.com/drive/api/v3/ref-search-terms

func (*Service) UpdateFile

func (svc *Service) UpdateFile(id, name string, src io.Reader) (*drive.File, error)

UpdateFile replaces an existing drive file (id) the contents read from 'src' and updates its name to 'name'

Jump to

Keyboard shortcuts

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