drive

package
v1.0.58 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package drive provides a client for the Google Drive API.

Index

Constants

View Source
const (
	MimeTypeFolder       = "application/vnd.google-apps.folder"
	MimeTypeDocument     = "application/vnd.google-apps.document"
	MimeTypeSpreadsheet  = "application/vnd.google-apps.spreadsheet"
	MimeTypePresentation = "application/vnd.google-apps.presentation"
	MimeTypeDrawing      = "application/vnd.google-apps.drawing"
	MimeTypeForm         = "application/vnd.google-apps.form"
	MimeTypeSite         = "application/vnd.google-apps.site"
	MimeTypeShortcut     = "application/vnd.google-apps.shortcut"
)

MIME type constants for Google Workspace files

Variables

This section is empty.

Functions

func GetExportMimeType added in v1.0.23

func GetExportMimeType(sourceMimeType, format string) (string, error)

GetExportMimeType returns the MIME type for exporting a Google Workspace file to the specified format. Returns an error if the format is not supported.

func GetFileExtension added in v1.0.23

func GetFileExtension(format string) string

GetFileExtension returns the appropriate file extension for a format

func GetSupportedExportFormats added in v1.0.23

func GetSupportedExportFormats(sourceMimeType string) []string

GetSupportedExportFormats returns the supported export formats for a Google Workspace file type

func GetTypeName

func GetTypeName(mimeType string) string

GetTypeName returns a human-readable name for a MIME type

func IsGoogleWorkspaceFile

func IsGoogleWorkspaceFile(mimeType string) bool

IsGoogleWorkspaceFile returns true if the MIME type is a Google Workspace file that requires export rather than direct download

Types

type Client

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

Client wraps the Google Drive API service

func NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient creates a new Drive client with OAuth2 authentication

func (*Client) DownloadFile added in v1.0.23

func (c *Client) DownloadFile(ctx context.Context, fileID string) ([]byte, error)

DownloadFile downloads a regular (non-Google Workspace) file

func (*Client) ExportFile added in v1.0.23

func (c *Client) ExportFile(ctx context.Context, fileID string, mimeType string) ([]byte, error)

ExportFile exports a Google Workspace file to the specified MIME type

func (*Client) GetFile

func (c *Client) GetFile(ctx context.Context, fileID string) (*File, error)

GetFile retrieves a single file by ID (supports files in shared drives)

func (*Client) ListFiles

func (c *Client) ListFiles(ctx context.Context, query string, pageSize int64) ([]*File, error)

ListFiles returns files matching the query (searches My Drive only for backwards compatibility)

func (*Client) ListFilesWithScope added in v1.0.32

func (c *Client) ListFilesWithScope(ctx context.Context, query string, pageSize int64, scope DriveScope) ([]*File, error)

ListFilesWithScope returns files matching the query within the specified scope

func (*Client) ListSharedDrives added in v1.0.32

func (c *Client) ListSharedDrives(ctx context.Context, pageSize int64) ([]*SharedDrive, error)

ListSharedDrives returns all shared drives accessible to the user

func (*Client) SearchFileIDs added in v1.0.37

func (c *Client) SearchFileIDs(ctx context.Context, query string, pageSize int64) ([]string, error)

SearchFileIDs returns only file IDs matching the query (no metadata fetch). This is more efficient than ListFiles when only IDs are needed.

func (*Client) StarFile added in v1.0.37

func (c *Client) StarFile(ctx context.Context, fileID string) error

StarFile stars a file in Drive

func (*Client) UnstarFile added in v1.0.37

func (c *Client) UnstarFile(ctx context.Context, fileID string) error

UnstarFile removes the star from a file in Drive

type DriveScope added in v1.0.32

type DriveScope struct {
	AllDrives   bool   // Search everywhere (My Drive + all shared drives)
	MyDriveOnly bool   // Restrict to personal My Drive only
	DriveID     string // Specific shared drive ID
}

DriveScope defines where to search for files

type File

type File struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	MimeType     string    `json:"mimeType"`
	Size         int64     `json:"size,omitempty"`
	CreatedTime  time.Time `json:"createdTime,omitempty"`
	ModifiedTime time.Time `json:"modifiedTime,omitempty"`
	Parents      []string  `json:"parents,omitempty"`
	Owners       []string  `json:"owners,omitempty"`
	WebViewLink  string    `json:"webViewLink,omitempty"`
	Shared       bool      `json:"shared"`
	DriveID      string    `json:"driveId,omitempty"` // Shared drive ID if file is in a shared drive
}

File represents a Google Drive file with simplified fields for JSON output

func ParseFile

func ParseFile(f *drive.File) *File

ParseFile converts a Google Drive API File to our simplified File struct

type SharedDrive added in v1.0.32

type SharedDrive struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

SharedDrive represents a Google Shared Drive (formerly Team Drive)

Jump to

Keyboard shortcuts

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