google

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 36 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package google has filers of Google's services, such as Tasks, whose requests are with the clients of package httpclient, so a request which isn't authorized returns an AuthError, which says a sign-in is needed.

Index

Constants

View Source
const (
	// SignInPrefix is the prefix of the keys of Google's credentials: the
	// client's, and the sign-ins, which are those other than the client's
	SignInPrefix = "GOOGLE_"

	// ClientCredential is the key of the credential of the OAuth client, a
	// desktop app's, which can redirect to a loopback address, as the JSON
	// of its client_id and client_secret, or the file Google's console
	// downloads, and DefaultCredential the key of a user's sign-in, a go-auth
	// Grant, which the credential parameter sets another of
	ClientCredential  = SignInPrefix + "CLIENT"
	DefaultCredential = SignInPrefix + "TOKEN"
)
View Source
const (
	// CalendarScheme is the scheme of the URL of a volume of a Google
	// account's calendars, gcalendar://<name>
	CalendarScheme = "gcalendar"

	// CalendarNamespace is the namespace of the metadata of events
	CalendarNamespace = "calendar"

	// DefaultCalendarWindow is the time of events, before today, and after
	// it, which are listed, unless the window parameter sets another
	DefaultCalendarWindow = 365 * day
)
View Source
const (
	// ContactsScheme is the scheme of the URL of a volume of a person's
	// Google Contacts, gcontacts://<name>
	ContactsScheme = "gcontacts"

	// ContactNamespace is the namespace of the metadata of contacts
	ContactNamespace = "contact"
)
View Source
const (
	// DriveScheme is the scheme of the URL of a volume of a person's Google
	// Drive, gdrive://<name>
	DriveScheme = "gdrive"

	// DriveNamespace is the namespace of the metadata of files, which their
	// content can't have: their ids, their links in Google Drive, who owns
	// them, and the type of those which are Google's own, such as document
	DriveNamespace = "drive"
)
View Source
const (
	// ProdID is the product which writes a task's iCalendar
	ProdID = "-//mutablelogic//go-filer//EN"

	// TaskNamespace is the namespace of the metadata of tasks and lists. A
	// list's folder:object-count and folder:subfolder-count are schema's.
	TaskNamespace = "task"

	// DCNamespace is the namespace of the Dublin Core metadata, whose
	// "title" is a list's, or a task's
	DCNamespace = "dc"
)
View Source
const (
	// TasksScheme is the scheme of a task filer's URL, such as
	// gtasks://tasks?readonly=false
	TasksScheme = "gtasks"

	// DefaultTasksQuota is the most requests each minute, unless the quota
	// parameter sets another
	DefaultTasksQuota = 120

	// DefaultRefreshInterval is how often changes are polled for, unless the
	// refresh_interval parameter sets another
	DefaultRefreshInterval = time.Minute
)
View Source
const (
	// NewTask is the name of the file, /<list>/~new.ics, which is written to
	// create a task, as Google gives a task its id, which can't have "~",
	// so it's never a task's
	NewTask = "~new"
)

Variables

View Source
var (
	// Google is the authorization server of Google accounts
	Google = authclient.ServerMetadata{
		Issuer:                        "https://accounts.google.com",
		AuthorizationEndpoint:         "https://accounts.google.com/o/oauth2/v2/auth",
		TokenEndpoint:                 "https://oauth2.googleapis.com/token",
		CodeChallengeMethodsSupported: []string{"S256"},
	}

	// SignInOptions are the options of the URL to sign in with Google at:
	// it asks for offline access, and consent, so Google issues a refresh
	// token, and includes the scopes the person has granted already
	SignInOptions = []oauth2.AuthCodeOption{
		oauth2.AccessTypeOffline,
		oauth2.SetAuthURLParam("prompt", "consent"),
		oauth2.SetAuthURLParam("include_granted_scopes", "true"),
	}
)

Functions

This section is empty.

Types

type CalendarFiler added in v0.5.0

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

CalendarFiler is a filer of the events of a Google account's calendars, of the days before today, and after it, of its window, as iCalendars, in a directory of each year, and of each month, such as /2026/2026-11/20-work@example.com-abc123.ics, which is the day it starts, in its own zone, its calendar, and its id. An event which repeats is an event of each time it occurs, so an event is of a day, which it starts on. It's read, and watched, and written of the event action, when it's writable.

func NewCalendarFiler added in v0.5.0

func NewCalendarFiler(ctx context.Context, name string, params url.Values, cache store.CacheStore, opts gofiler.Opts) (*CalendarFiler, error)

NewCalendarFiler returns a filer of the Google Calendar events of the volume's name, with the parameters, the user's sign-in, of the provider of credentials, and go-client's options of its requests. The sign-in, and the calendars, are checked, as for NewTaskFiler. Its parameters are readonly, which is true by default, and, when it's false, needs a sign-in which can write events, of the event action, quota, refresh_interval and credential, as a task filer's, and window, the time of events which are listed, before today, and after it, such as 30d, 52w, or 720h, which is DefaultCalendarWindow, of whole days.

func (*CalendarFiler) Actions added in v0.5.0

func (self *CalendarFiler) Actions() []gofiler.Action

Actions returns what the volume can do, beyond its objects, when it's writable: event, which creates, updates or deletes an event

func (*CalendarFiler) Clone added in v0.5.0

func (self *CalendarFiler) Clone(ctx context.Context, patch url.Values) (gofiler.Filer, error)

Clone returns a new filer of the calendars, with the parameters changed by the patch, and the same client options, which is checked as a new filer is

func (*CalendarFiler) Close added in v0.5.0

func (self *CalendarFiler) Close() error

Close the filer

func (*CalendarFiler) CreateObject added in v0.5.0

CreateObject isn't implemented, as events aren't written, so far

func (*CalendarFiler) DeleteObjects added in v0.5.0

DeleteObjects isn't implemented, as events aren't written, so far

func (*CalendarFiler) Description added in v0.5.0

func (self *CalendarFiler) Description() string

Description returns what the volume is, such as "Google Calendar for ada@example.com"

func (*CalendarFiler) GetObject added in v0.5.0

func (self *CalendarFiler) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)

GetObject returns the root, a year, or a month, which are directories, or an event

func (*CalendarFiler) ListObjects added in v0.5.0

ListObjects lists the years of the root, the months of a year, or the events of a month, or, when it's recursive, every directory and event beneath it, or only an event, in the order of their paths, after the path the request starts after

func (*CalendarFiler) ReadObject added in v0.5.0

ReadObject returns the function which reads an event's iCalendar, and the event. A directory can't be read, which is fs.ErrInvalid.

func (*CalendarFiler) Readonly added in v0.5.0

func (self *CalendarFiler) Readonly() bool

Readonly returns true when events can't be created, updated or deleted, of the event action

func (*CalendarFiler) URL added in v0.5.0

func (self *CalendarFiler) URL() *url.URL

URL returns the URL of the filer, such as gcalendar://calendar, with each of its parameters

func (*CalendarFiler) WatchObjects added in v0.5.0

func (self *CalendarFiler) WatchObjects(ctx context.Context, ch chan<- schema.Event) error

WatchObjects polls each calendar for its changes since its sync token, at the refresh interval, and sends them, until the context is cancelled: an event which is created, updated, moved, which is deleted where it was, or cancelled, of where the events which were listed are, as a change doesn't say where an event was. The root is rescanned instead when that can't be said: when an event which repeats changed, as a sync is of it, rather than the times it occurs, nothing has been listed, a calendar is added, removed, or changed, such as renamed, which its events' content is of, a calendar's token was rejected, so its changes may have been missed, or the days which are listed move on. The first change is a rescan of the root, once the calendars are watched. What the filer writes, of the event action, is sent as it's written, rather than when it's synced, and isn't sent again when it is (see wrote).

The tokens are stored, with the provider of credentials, of the sign-in (see calendarSyncKey), so after a restart, the changes since they were stored are found. Volumes of the same sign-in share them, as they're of its calendars, rather than of a window, so one which is synced of another's earlier token rescans what changed since, again. A calendar without one is synced for one. A token which Google rejects, as it's expired, is synced again, which a calendar is, at most, each calendarResyncInterval. Returns ErrNotImplemented when the refresh interval is zero, and the error of reading them, such as a SignInError, when a sign-in is needed. Reference: https://developers.google.com/calendar/api/guides/sync

type ContactFiler added in v0.5.0

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

ContactFiler is a filer of a person's Google Contacts: each contact is a file at the root, of its id, as a vCard, with its metadata, such as its name. It's read, and watched, and written, when it's writable, of the contact action.

func NewContactFiler added in v0.5.0

func NewContactFiler(ctx context.Context, name string, params url.Values, cache store.CacheStore, opts gofiler.Opts) (*ContactFiler, error)

NewContactFiler returns a filer of the Google Contacts of the volume's name, with the parameters, the user's sign-in, of the provider of credentials, and go-client's options of its requests, such as a tracer. The sign-in, and the contacts, are checked, as for NewTaskFiler, and its parameters are readonly, which is true by default, and, when it's false, needs a sign-in which can write contacts, of the contact action, quota, refresh_interval and credential, as a task filer's.

func (*ContactFiler) Actions added in v0.5.0

func (self *ContactFiler) Actions() []gofiler.Action

Actions returns what the volume can do, beyond its objects, when it's writable: contact, which creates, updates or deletes a contact

func (*ContactFiler) Clone added in v0.5.0

func (self *ContactFiler) Clone(ctx context.Context, patch url.Values) (gofiler.Filer, error)

Clone returns a new filer of the contacts, with the parameters changed by the patch, and the same client options, which is checked as a new filer is

func (*ContactFiler) Close added in v0.5.0

func (self *ContactFiler) Close() error

Close the filer

func (*ContactFiler) CreateObject added in v0.5.0

CreateObject isn't implemented, as contacts aren't written, so far

func (*ContactFiler) DeleteObjects added in v0.5.0

DeleteObjects isn't implemented, as contacts aren't written, so far

func (*ContactFiler) Description added in v0.5.0

func (self *ContactFiler) Description() string

Description returns what the volume is, such as "Google Contacts for ada@example.com"

func (*ContactFiler) GetObject added in v0.5.0

func (self *ContactFiler) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)

GetObject returns the root, which is a directory, or a contact

func (*ContactFiler) ListObjects added in v0.5.0

ListObjects lists the root, which is its contacts, in the order of their paths, whether or not it's recursive, or a contact, after the path the request starts after

func (*ContactFiler) ReadObject added in v0.5.0

ReadObject returns the function which reads a contact's vCard, and the contact. The root can't be read, which is fs.ErrInvalid.

func (*ContactFiler) Readonly added in v0.5.0

func (self *ContactFiler) Readonly() bool

Readonly returns true unless the volume is writable, with readonly=false

func (*ContactFiler) URL added in v0.5.0

func (self *ContactFiler) URL() *url.URL

URL returns the URL of the filer, such as gcontacts://contacts, with each of its parameters

func (*ContactFiler) WatchObjects added in v0.5.0

func (self *ContactFiler) WatchObjects(ctx context.Context, ch chan<- schema.Event) error

WatchObjects syncs the contacts, at the refresh interval, of the token of the changes since it last did, and sends what changed, until the context is cancelled: a contact which is created, or whose entity tag changes, or which is deleted. While it's watched, the filer reads the contacts it knows, rather than getting them again.

The contacts, and their token, are saved in the volume's cache, so a watch which starts again, such as after a restart, syncs what changed since, rather than getting every contact. The first change is a rescan of the root, once they're known. When Google doesn't accept the token, such as one which is more than seven days old, every contact is got again, and the root is rescanned. When Google is unavailable, it's synced again at the next interval. One watch of a filer is at a time, and another is ErrConflict. Returns ErrNotImplemented when the refresh interval is zero, and the error of reading them, such as a SignInError, when a sign-in is needed. Reference: https://developers.google.com/people/v1/contacts#sync_the_users_contacts

type DriveFiler added in v0.5.0

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

DriveFiler is a filer of the files a person owns in their Google Drive's My Drive, by their paths, whose folders are directories, and whose Google Docs, Sheets and Slides are Word, Excel and PowerPoint documents. It's read, and watched, and written, when it's writable, of its files, but not of its Docs, Sheets and Slides, and what's deleted goes to its bin.

func NewDriveFiler added in v0.5.0

func NewDriveFiler(ctx context.Context, name string, params url.Values, cache store.CacheStore, opts gofiler.Opts) (*DriveFiler, error)

NewDriveFiler returns a filer of the Google Drive of the volume's name, with the parameters, the user's sign-in, of the provider of credentials, and go-client's options of its requests, such as a tracer. The sign-in, and the files, are checked, as for NewTaskFiler, and its parameters are readonly, which is true by default, and, when it's false, needs a sign-in which can write files, of the drive scope, quota, and credential, as a task filer's, and refresh_interval, how often changes are polled for, when it's watched, and how long the files are kept, once they're got, when it isn't, which is DefaultRefreshInterval, or zero not to watch it, nor keep them.

func (*DriveFiler) Actions added in v0.5.0

func (self *DriveFiler) Actions() []gofiler.Action

Actions returns none, as a drive is written of its objects

func (*DriveFiler) Clone added in v0.5.0

func (self *DriveFiler) Clone(ctx context.Context, patch url.Values) (gofiler.Filer, error)

Clone returns a new filer of the drive, with the parameters changed by the patch, and the same client options, which is checked as a new filer is

func (*DriveFiler) Close added in v0.5.0

func (self *DriveFiler) Close() error

Close the filer

func (*DriveFiler) CreateObject added in v0.5.0

func (self *DriveFiler) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (*schema.Object, error)

CreateObject uploads a file, as it's read, of its path, which is a new revision of the file at the path, when there's one, keeping its id, link, and who it's shared with, or a new file, in the folders of its path, which are created when they aren't there. Its type is the request's, or its extension's, and its modification time the request's, when it's set. A file isn't written over a folder, nor over a Google Doc, Sheet or Slides, which is ErrForbidden, as their content is an export, nor of a name which is hidden, which isn't listed, or which starts, or ends, with a space, which a name isn't listed with, nor of a name which is another's in its folder, ignoring case, which would rename both, and, of IfNotExists, over a file, nor, of IfExists, where there's none. Its metadata isn't written, so far.

A new file's folders, and the file, without content, are created first, with its name, which only one create does at a time, so two creates of a path don't both create it, and its content is then uploaded, as a new revision of it, at the same time as others'. A folder which is created stays, when the upload fails, but a new file is binned.

func (*DriveFiler) DeleteObjects added in v0.5.0

DeleteObjects moves a file, or, when it's recursive, a folder, with what's in it, to the bin, from which it can be restored, and returns the files which are deleted, but not the folders. The root can't be deleted, nor a folder, unless it's recursive.

func (*DriveFiler) Description added in v0.5.0

func (self *DriveFiler) Description() string

Description returns what the volume is, such as "Google Drive for ada@example.com"

func (*DriveFiler) GetObject added in v0.5.0

func (self *DriveFiler) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)

GetObject returns the root, a folder, which is a directory, or a file

func (*DriveFiler) ListObjects added in v0.5.0

ListObjects lists a directory, of the files, and directories, in it, or, when it's recursive, beneath it, or a file, in the order of their paths, after the path the request starts after

func (*DriveFiler) ReadObject added in v0.5.0

ReadObject returns the function which reads a file, and the file. A file is read of its revision when it was listed, so its content is the file's, though it's changed since, and can seek, and be read at an offset, so it's read in place, of the ranges which are read (see driveReader). A Google Doc, Sheet or Slides is exported, which can't be of a version, so it's read into memory, and its version is checked before, and after, which is ErrPreconditionFailed, when it's changed since it was listed. An error of the function is returned as it is. A directory can't be read, which is fs.ErrInvalid.

func (*DriveFiler) Readonly added in v0.5.0

func (self *DriveFiler) Readonly() bool

Readonly returns true unless the volume is writable, with readonly=false

func (*DriveFiler) URL added in v0.5.0

func (self *DriveFiler) URL() *url.URL

URL returns the URL of the filer, such as gdrive://drive, with each of its parameters

func (*DriveFiler) WatchObjects added in v0.5.0

func (self *DriveFiler) WatchObjects(ctx context.Context, ch chan<- schema.Event) error

WatchObjects polls the changes to the files, at the refresh interval, and sends them, until the context is cancelled. Each change is applied to the files, and their paths are made again, so a path which is new is created, one whose file changed, such as its content, is updated, and one which is gone, such as when its file, or its folder, moved, was renamed, or was binned, is deleted. While it's watched, the filer lists, and reads, the files it knows, rather than getting them again.

The first change is a rescan of the root, once the files are listed, of the token of the changes from before they were, so a change as they're listed is applied again, which changes nothing. When Google doesn't accept the token, such as one which has expired, the files are listed again, of another, and the root is rescanned. When Google is unavailable, it's polled again at the next interval, rather than listing the files again, nor when the files are to be listed again, when they're listed at the next interval, and the files it knows are kept until then. One watch of a filer is at a time, and another is ErrConflict. Returns ErrNotImplemented when the refresh interval is zero, and the error of listing them, such as a SignInError, when a sign-in is needed. Reference: https://developers.google.com/drive/api/guides/manage-changes

type TaskFiler added in v0.5.0

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

TaskFiler is a filer of Google Tasks: each task list is a directory, of its id, and each task a file, of its id, as an iCalendar of its VTODO, with its metadata, such as its due date

func NewTaskFiler added in v0.5.0

func NewTaskFiler(ctx context.Context, name string, params url.Values, cache store.CacheStore, opts gofiler.Opts) (*TaskFiler, error)

NewTaskFiler returns a filer of the Google Tasks of the volume's name, with the parameters, the user's sign-in, of the provider of credentials, and go-client's options of its requests, such as a tracer. The sign-in is checked, and the tasks, so a sign-in which is needed is an SignInError, with how to sign in, which is when there isn't one, or it's for another client than ClientCredential's, or it doesn't have the access the volume needs. The parameters are:

  • readonly: tasks can't be created, updated or deleted, which is true unless it's false, which needs the tasks scope, rather than tasks.readonly
  • credential: the key of the sign-in, which is DefaultCredential
  • quota: the most requests each minute, which is DefaultTasksQuota, or zero not to limit them
  • refresh_interval: how often changes are polled for, when they're watched, which is DefaultRefreshInterval, or zero not to watch them
  • hidden: tasks which are hidden, as they're completed, and cleared from their list, are included, which they aren't unless it's true

func (*TaskFiler) Actions added in v0.5.0

func (self *TaskFiler) Actions() []gofiler.Action

Actions returns what the volume can do, beyond its objects, when it's writable: task_list, which creates, renames or deletes a list, and task, which creates, updates or deletes a task

func (*TaskFiler) Clone added in v0.5.0

func (self *TaskFiler) Clone(ctx context.Context, patch url.Values) (gofiler.Filer, error)

Clone returns a new filer of the tasks, with the parameters changed by the patch, and the same client options, which is checked as a new filer is

func (*TaskFiler) Close added in v0.5.0

func (self *TaskFiler) Close() error

Close the filer

func (*TaskFiler) CreateObject added in v0.5.0

func (self *TaskFiler) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (*schema.Object, error)

CreateObject writes a task, of an iCalendar of one VTODO. Writing /<list>/~new.ics creates a task, which is returned at its path, of the id Google gives it, and writing a task's path replaces the fields a VTODO has: its title, notes, due date and status, which are cleared when it doesn't have them, and its parent, when it's changed, which moves it. Its other fields, such as its links, are kept. A task which doesn't exist isn't found, as a task's id can't be chosen.

func (*TaskFiler) DeleteObjects added in v0.5.0

DeleteObjects deletes a task, with its subtasks, as Google does, or a list, with its tasks, when the request is recursive, and returns the tasks which were deleted, and the list, after them, as a list is an object of its own, rather than a directory which is there while it has tasks. The root can't be deleted, which is ErrBadParameter, nor a list which isn't recursive, which is ErrConflict, as a directory isn't.

func (*TaskFiler) Description added in v0.5.0

func (self *TaskFiler) Description() string

Description returns what the volume is, such as "Google Tasks for ada@example.com"

func (*TaskFiler) GetObject added in v0.5.0

func (self *TaskFiler) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)

GetObject returns the root, a list, which is a directory, or a task, which is a file. Returns ErrNotModified when the request's conditions say the object hasn't changed, and fs.ErrNotExist when it doesn't exist.

func (*TaskFiler) ListObjects added in v0.5.0

ListObjects lists the lists, and, when it's recursive, their tasks, of the root, or a list's tasks, or only a task, in the order of their paths. The objects which sort at, or before, StartAfter aren't returned. A list which doesn't exist is fs.ErrNotExist.

func (*TaskFiler) ReadObject added in v0.5.0

ReadObject returns the function which reads a task's iCalendar, and the task. A list, or the root, can't be read, which is fs.ErrInvalid.

func (*TaskFiler) Readonly added in v0.5.0

func (self *TaskFiler) Readonly() bool

Readonly returns true when tasks can't be created, updated or deleted

func (*TaskFiler) URL added in v0.5.0

func (self *TaskFiler) URL() *url.URL

URL returns the URL of the filer, such as gtasks://tasks, with each of its parameters

func (*TaskFiler) WatchObjects added in v0.5.0

func (self *TaskFiler) WatchObjects(ctx context.Context, ch chan<- schema.Event) error

WatchObjects polls the lists and tasks, at the refresh interval, and sends the changes, until the context is cancelled: a list or task which is created, or whose entity tag changes, or which is deleted. A list which is deleted is the deletion of each of its tasks, and of the list. What the filer creates, updates or deletes is sent as it's changed, rather than when it's refreshed, and isn't sent again when it is. Returns ErrNotImplemented when the refresh interval is zero, and the error of reading them, such as an AuthError, when a sign-in is needed.

Directories

Path Synopsis
Package httpclient has clients of Google's APIs, with go-auth's auth/httpclient, so a request which isn't authorized returns an AuthError, which says a sign-in is needed.
Package httpclient has clients of Google's APIs, with go-auth's auth/httpclient, so a request which isn't authorized returns an AuthError, which says a sign-in is needed.

Jump to

Keyboard shortcuts

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