googledrive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package googledrive provides an abstraction layer over the Google Drive API. It simplifies creating and uploading files to Google Drive by wrapping the complex API calls into more manageable functions.

Index

Constants

View Source
const (
	// roles
	OwnerRole         = "owner"
	OrganizerRole     = "organizer"
	FileOrganizerRole = "fileOrganizer"
	WriterRole        = "writer"
	CommenterRole     = "commenter"
	ReaderRole        = "reader"

	// grantee types
	UserGranteeType   = "user"
	GroupGranteeType  = "group"
	DomainGranteeType = "domain"
	AnyoneGranteeType = "anyone"
)

Constant definitions for various roles and grantee types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// CreateFolder creates a new folder in Google Drive with the specified name.
	// The new folder can optionally be created within specified parent folders.
	// Returns the ID of the created folder or an error if the operation fails.
	CreateFolder(folderName string, parentFolders ...string) (string, error)

	// UploadFile uploads a file to Google Drive.
	// The file to upload is specified as an os.File pointer.
	// The file can optionally be uploaded within specified parent folders.
	// Returns the ID of the uploaded file or an error if the operation fails.
	UploadFile(file *os.File, parentFolders ...string) (string, error)

	// UpdateFile updates the content of an existing file in Google Drive.
	// The file to update is specified by its file ID, and the new content is
	// provided as an os.File pointer.
	// Returns the ID of the updated file or an error if the operation fails.
	UpdateFile(fileId string, newContent *os.File) (string, error)

	// GetFileById retrieves the details of a file from Google Drive using its file ID.
	// Returns a drive.File object containing file details or an error if retrieval fails.
	GetFileById(fileId string) (*drive.File, error)

	// DeleteFile deletes a file from Google Drive using its file ID.
	// Returns an error if the deletion operation fails.
	DeleteFile(fileId string) error

	// AssignRoleToUserOnFile assigns a specified role to a user for a file in Google Drive.
	// The role, user's email address, and file ID are specified.
	// Returns an error if the role assignment operation fails.
	AssignRoleToUserOnFile(role, emailAddress, fileId string) error

	// AssignRoleToGroupOnFile assigns a specified role to a group for a file in Google Drive.
	// The role, group's email address, and file ID are specified.
	// Returns an error if the role assignment operation fails.
	AssignRoleToGroupOnFile(role, emailAddress, fileId string) error

	// AssignRoleToDomainOnFile assigns a specified role to a domain for a file in Google Drive.
	// The role, domain, and file ID are specified.
	// Returns an error if the role assignment operation fails.
	AssignRoleToDomainOnFile(role, domain, fileId string) error

	// AssignRoleToAnyoneOnFile assigns a specified role to anyone for a file in Google Drive.
	// The role and file ID are specified.
	// Returns an error if the role assignment operation fails.
	AssignRoleToAnyoneOnFile(role, fileId string) error

	// DownloadFile downloads a file from Google Drive using its file ID.
	// The downloaded file is saved to the specified outputFile path.
	// Returns the path of the downloaded file or an error if the download operation fails.
	DownloadFile(fileId, outputFile string) (string, error)
}

Client defines the interface for interacting with Google Drive.

func New

func New(ctx context.Context, credsFilePath string) (Client, error)

New creates a new Client instance for interacting with Google Drive. It initializes the drive service with the provided context and credentials file.

Jump to

Keyboard shortcuts

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