calendar

package
v0.0.142 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package calendar provides a client for interacting with the Google Calendar API.

This package offers functionality for managing calendars and calendar events, including creating, reading, updating, and deleting events, as well as checking availability and finding available time slots for scheduling meetings.

The client supports multi-account authentication using the Google OAuth2 flow and can manage events across multiple Google accounts.

Example usage:

ctx := context.Background()
client, err := calendar.NewClient(ctx)
if err != nil {
    log.Fatal(err)
}

// List upcoming events
events, err := client.ListEvents("primary", time.Now(), time.Now().AddDate(0, 0, 7), "")
if err != nil {
    log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasToken

func HasToken() bool

HasToken checks if a valid OAuth token exists for the default account

func HasTokenForAccount

func HasTokenForAccount(account string) bool

HasTokenForAccount checks if a valid OAuth token exists for the specified account

func HasTokenForAccountWithProvider added in v0.0.27

func HasTokenForAccountWithProvider(account string, provider google.TokenProvider) bool

HasTokenForAccountWithProvider checks if a valid OAuth token exists for the specified account

Types

type AttendeeInfo

type AttendeeInfo struct {
	Email          string
	DisplayName    string
	ResponseStatus string // "needsAction", "declined", "tentative", "accepted"
	Optional       bool
	Organizer      bool
}

AttendeeInfo represents information about an event attendee

type AvailableSlot

type AvailableSlot struct {
	Start    time.Time
	End      time.Time
	Duration time.Duration
}

AvailableSlot represents an available time slot for scheduling

type CalendarInfo

type CalendarInfo struct {
	ID          string
	Summary     string
	Description string
	TimeZone    string
	Primary     bool
	AccessRole  string // "owner", "writer", "reader", "freeBusyReader"
}

CalendarInfo represents information about a calendar

type Client

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

Client wraps the Google Calendar service

func NewClient

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

NewClient creates a new Calendar client with OAuth2 authentication for the default account For CLI usage, it will prompt for auth code via stdin if no token exists For MCP usage, it will return an error if no token exists

func NewClientForAccount

func NewClientForAccount(ctx context.Context, account string) (*Client, error)

NewClientForAccount creates a new Calendar client with OAuth2 authentication for a specific account Uses the default file-based token provider for backward compatibility

func NewClientForAccountWithProvider added in v0.0.27

func NewClientForAccountWithProvider(ctx context.Context, account string, tokenProvider google.TokenProvider) (*Client, error)

NewClientForAccountWithProvider creates a new Calendar client with OAuth2 authentication for a specific account The OAuth token is retrieved from the provided token provider

func NewClientWithProvider added in v0.0.27

func NewClientWithProvider(ctx context.Context, provider google.TokenProvider) (*Client, error)

NewClientWithProvider creates a new Calendar client with OAuth2 authentication for the default account using the provided token provider

func (*Client) Account

func (c *Client) Account() string

Account returns the account name this client is associated with

func (*Client) CreateEvent

func (c *Client) CreateEvent(calendarID string, input EventInput) (*EventSummary, error)

CreateEvent creates a new calendar event

func (*Client) DeleteEvent

func (c *Client) DeleteEvent(calendarID, eventID string) error

DeleteEvent deletes a calendar event

func (c *Client) ExtractGoogleDocsLinks(calendarID, eventID string) ([]string, error)

ExtractGoogleDocsLinks extracts Google Docs links from an event

func (*Client) FindAvailableSlots

func (c *Client) FindAvailableSlots(attendees []string, duration time.Duration, timeMin, timeMax time.Time) ([]AvailableSlot, error)

FindAvailableSlots finds available time slots for scheduling a meeting It checks the availability of all specified attendees and returns slots where everyone is free

func (*Client) GetCalendar

func (c *Client) GetCalendar(calendarID string) (*CalendarInfo, error)

GetCalendar retrieves information about a specific calendar

func (*Client) GetEvent

func (c *Client) GetEvent(calendarID, eventID string) (*EventSummary, error)

GetEvent retrieves a specific event by ID

func (c *Client) GetGoogleMeetLink(calendarID, eventID string) (string, error)

GetGoogleMeetLink retrieves the Google Meet link from an event

func (*Client) GetPrimaryCalendar

func (c *Client) GetPrimaryCalendar() (*CalendarInfo, error)

GetPrimaryCalendar retrieves information about the primary calendar

func (*Client) ListCalendars

func (c *Client) ListCalendars() ([]CalendarInfo, error)

ListCalendars lists all calendars accessible to the user

func (*Client) ListEvents

func (c *Client) ListEvents(calendarID string, timeMin, timeMax time.Time, query string) ([]EventSummary, error)

ListEvents lists events in a calendar within a time range

func (*Client) QueryFreeBusy

func (c *Client) QueryFreeBusy(timeMin, timeMax time.Time, calendarIDs []string) ([]FreeBusyInfo, error)

QueryFreeBusy checks availability for calendars in a time range

func (*Client) UpdateEvent

func (c *Client) UpdateEvent(calendarID, eventID string, input EventInput) (*EventSummary, error)

UpdateEvent updates an existing calendar event

type EventInput

type EventInput struct {
	Summary     string
	Description string
	Location    string
	Start       time.Time
	End         time.Time
	TimeZone    string
	Attendees   []string
	Recurrence  []string // RRULE, EXRULE, RDATE, EXDATE
	AllDay      bool     // If true, creates an all-day event

	// Event type: "default", "outOfOffice", "focusTime", "workingLocation"
	EventType string

	// Guest permissions
	GuestsCanModify         bool
	GuestsCanInviteOthers   bool
	GuestsCanSeeOtherGuests bool

	// Conference data
	UseDefaultConferenceData bool // Automatically add Google Meet
}

EventInput represents the input for creating or updating a calendar event

type EventSummary

type EventSummary struct {
	ID          string
	Summary     string
	Description string
	Location    string
	Start       time.Time
	End         time.Time
	Creator     string
	Organizer   string
	Status      string
	Attendees   []AttendeeInfo
	MeetLink    string
	EventType   string
}

EventSummary represents a simplified calendar event for listing

type FreeBusyInfo

type FreeBusyInfo struct {
	Calendar string
	Busy     []TimeRange
	Errors   []string
}

FreeBusyInfo represents availability information for a calendar

type TimeRange

type TimeRange struct {
	Start time.Time
	End   time.Time
}

TimeRange represents a time range

Jump to

Keyboard shortcuts

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