google

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements GoogleClient using Google Drive and Cloud Identity APIs.

func NewClient

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

NewClient creates a new Google API client using service account credentials.

func NewClientFromJSON

func NewClientFromJSON(
	ctx context.Context,
	credentialsJSON []byte,
) (*Client, error)

NewClientFromJSON creates a new Google API client using raw service account credentials JSON, avoiding the need to write credentials to a temporary file.

func (*Client) Close

func (c *Client) Close()

Close releases resources held by the client, including idle HTTP connections.

func (*Client) DownloadFile

func (c *Client) DownloadFile(
	ctx context.Context,
	fileID string,
	maxRetries int,
) (io.ReadCloser, error)

DownloadFile downloads the content of a file. It handles three cases in order:

  1. Native Google Workspace files (Docs, Sheets, Slides, Drawings) — exported as PDF via direct Docs editor URLs.
  2. Uploaded files that Google can open in a Workspace editor (DOCX, XLSX, PPTX, etc.) — also exported as PDF via Docs editor URLs, determined by Drive importFormats.
  3. All other files — downloaded as raw binary via Drive API.

The caller must close the returned ReadCloser.

func (*Client) GetFileMetadata

func (c *Client) GetFileMetadata(
	ctx context.Context,
	fileID string,
	maxRetries int,
) (*drive.File, error)

GetFileMetadata retrieves metadata for a single file or folder.

func (*Client) GetFilePermissions

func (c *Client) GetFilePermissions(
	ctx context.Context,
	fileID string,
	maxRetries int,
) ([]*drive.Permission, error)

GetFilePermissions retrieves all permissions for a given file ID from the Drive API with retry support.

func (*Client) GetGroupMembers

func (c *Client) GetGroupMembers(
	ctx context.Context,
	groupEmail string,
) ([]string, error)

GetGroupMembers retrieves all transitive members of a Google group by email. It uses Cloud Identity API to expand nested group memberships.

func (*Client) IsFolderAccessible

func (c *Client) IsFolderAccessible(
	ctx context.Context,
	folderID string,
) bool

IsFolderAccessible checks if a folder can be accessed by the service account.

func (*Client) ListFolderContents

func (c *Client) ListFolderContents(
	ctx context.Context,
	folderID string,
	maxRetries int,
) ([]*drive.File, error)

ListFolderContents lists all items in a folder with full metadata. Uses pagination and retries on transient errors.

type GoogleClient

type GoogleClient interface {
	GetFilePermissions(
		ctx context.Context, fileID string, maxRetries int,
	) ([]*drive.Permission, error)
	GetGroupMembers(
		ctx context.Context, groupEmail string,
	) ([]string, error)
	ListFolderContents(
		ctx context.Context, folderID string, maxRetries int,
	) ([]*drive.File, error)
	GetFileMetadata(
		ctx context.Context, fileID string, maxRetries int,
	) (*drive.File, error)
	IsFolderAccessible(
		ctx context.Context, folderID string,
	) bool
	DownloadFile(
		ctx context.Context, fileID string, maxRetries int,
	) (io.ReadCloser, error)
	Close()
}

GoogleClient defines the interface for Google API operations used by the gdrive package.

Jump to

Keyboard shortcuts

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