googledrive

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 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 struct {
	// contains filtered or unexported fields
}

Client provides functions to interact with Google Drive's file and permission services.

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.

func (*Client) AssignRoleToAnyoneOnFile

func (c *Client) AssignRoleToAnyoneOnFile(role, 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.

func (*Client) AssignRoleToDomainOnFile

func (c *Client) AssignRoleToDomainOnFile(role, domain, 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.

func (*Client) AssignRoleToGroupOnFile

func (c *Client) AssignRoleToGroupOnFile(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.

func (*Client) AssignRoleToUserOnFile

func (c *Client) AssignRoleToUserOnFile(role, emailAddress, 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.

func (*Client) CreateFolder

func (c *Client) CreateFolder(folderName string, parentFolders ...string) (string, error)

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.

func (*Client) DeleteFile

func (c *Client) DeleteFile(fileId string) error

DeleteFile deletes a file from Google Drive using its file ID. Returns an error if the deletion operation fails.

func (*Client) DownloadFile

func (c *Client) DownloadFile(fileId, outputFile string) (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.

func (*Client) GetFileById

func (c *Client) GetFileById(fileId string) (*drive.File, 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.

func (*Client) UpdateFile

func (c *Client) UpdateFile(fileId string, newContent *os.File) (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.

func (*Client) UploadFile

func (c *Client) UploadFile(file *os.File, 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.

Jump to

Keyboard shortcuts

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