gdrive

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeSource

type ChangeSource struct {
	Source
}

ChangeSource is an IncrementalSource backed by the Google Drive Changes API. It embeds Source to reuse authentication, full Walk, GetFileStream, and metadata conversion.

func NewChangeSource

func NewChangeSource(ctx context.Context, opts ...Option) (*ChangeSource, error)

func (*ChangeSource) GetStartPageToken

func (s *ChangeSource) GetStartPageToken() (string, error)

GetStartPageToken returns the token representing the current head of the Google Drive change stream.

func (*ChangeSource) Info

func (s *ChangeSource) Info() source.SourceInfo

func (*ChangeSource) WalkChanges

func (s *ChangeSource) WalkChanges(ctx context.Context, token string, callback func(source.FileChange) error) (string, error)

WalkChanges iterates over all changes since the given page token. Folder changes are emitted before file changes so that the engine can resolve parent references incrementally.

type Option

type Option func(*gDriveOptions)

Option configures a Google Drive source.

func WithAccountEmail

func WithAccountEmail(email string) Option

WithAccountEmail explicitly sets the account email instead of calling the API.

func WithCredsJSON

func WithCredsJSON(data []byte) Option

WithCredsJSON provides credentials as raw JSON bytes (inline). Supports both OAuth-client and service-account credential formats. This mirrors rclone's service_account_credentials option.

func WithCredsPath

func WithCredsPath(path string) Option

WithCredsPath sets the path to the credentials JSON file. If empty, uses the built-in OAuth client.

func WithCredsRef

func WithCredsRef(ref string) Option

WithCredsRef sets the secret reference to the credentials JSON.

func WithDriveID

func WithDriveID(id string) Option

WithDriveID sets the shared drive ID. If empty, defaults to "My Drive".

func WithDriveName

func WithDriveName(name string) Option

WithDriveName sets the shared drive name to use. It will be resolved to a Drive ID.

func WithDriveService

func WithDriveService(srv *drive.Service) Option

WithDriveService injects a fully-constructed *drive.Service. When set, all credential/token options are ignored — the caller is responsible for scopes, token refresh, etc.

func WithExcludePatterns

func WithExcludePatterns(patterns []string) Option

WithExcludePatterns sets the patterns used to exclude files and folders.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client for OAuth.

func WithLogger

func WithLogger(w io.Writer) Option

WithLogger sends this source's debug output to w.

Sources are constructed independently of a client, so a client's sink cannot reach them; this is how a caller supplies one (RFC 0022 §8).

func WithResolver

func WithResolver(r *secretref.Resolver) Option

WithResolver sets the secret resolver for ref-based auth.

func WithRootFolderID

func WithRootFolderID(id string) Option

WithRootFolderID sets the root folder ID directly (for client API).

func WithRootPath

func WithRootPath(path string) Option

WithRootPath sets the path to the root folder. This is resolved to a folder ID during initialization.

func WithSkipNativeFiles

func WithSkipNativeFiles() Option

WithSkipNativeFiles excludes Google-native files (Docs, Sheets, Slides, etc.) from the backup. They will not appear in the snapshot at all.

func WithTokenPath

func WithTokenPath(path string) Option

WithTokenPath sets the path where the OAuth token is cached.

func WithTokenRef

func WithTokenRef(ref string) Option

WithTokenRef sets the secret reference where the OAuth token is cached.

type Source

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

Source implements Source for Google Drive. By default it backs up the entire "My Drive" root. Set DriveID in SourceConfig to back up a shared drive instead, and/or set RootFolderID to restrict to a specific folder within the selected drive.

func New

func New(ctx context.Context, opts ...Option) (*Source, error)

New creates a new Source from the given options.

func (*Source) GetFileStream

func (s *Source) GetFileStream(fileID string) (io.ReadCloser, error)

func (*Source) Info

func (s *Source) Info() source.SourceInfo

func (*Source) Size

func (s *Source) Size(ctx context.Context) (*source.SourceSize, error)

Size returns the total size of the drive. For My Drive it uses the fast about.get endpoint. For shared drives it lists all files and sums sizes.

func (*Source) Walk

func (s *Source) Walk(ctx context.Context, callback func(source.FileMeta) error) error

Walk lists all files from Drive. Folders are accumulated in memory (necessary for topological sort) but files are streamed page-by-page to avoid holding the full file list in memory.

Jump to

Keyboard shortcuts

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