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 ¶
- func HasToken() bool
- func HasTokenForAccount(account string) bool
- func HasTokenForAccountWithProvider(account string, provider google.TokenProvider) bool
- type AttendeeInfo
- type AvailableSlot
- type CalendarInfo
- type Client
- func NewClient(ctx context.Context) (*Client, error)
- func NewClientForAccount(ctx context.Context, account string) (*Client, error)
- func NewClientForAccountWithProvider(ctx context.Context, account string, tokenProvider google.TokenProvider) (*Client, error)
- func NewClientWithProvider(ctx context.Context, provider google.TokenProvider) (*Client, error)
- func (c *Client) Account() string
- func (c *Client) CreateEvent(calendarID string, input EventInput) (*EventSummary, error)
- func (c *Client) DeleteEvent(calendarID, eventID string) error
- func (c *Client) ExtractGoogleDocsLinks(calendarID, eventID string) ([]string, error)
- func (c *Client) FindAvailableSlots(attendees []string, duration time.Duration, timeMin, timeMax time.Time) ([]AvailableSlot, error)
- func (c *Client) GetCalendar(calendarID string) (*CalendarInfo, error)
- func (c *Client) GetEvent(calendarID, eventID string) (*EventSummary, error)
- func (c *Client) GetGoogleMeetLink(calendarID, eventID string) (string, error)
- func (c *Client) GetPrimaryCalendar() (*CalendarInfo, error)
- func (c *Client) ListCalendars() ([]CalendarInfo, error)
- func (c *Client) ListEvents(calendarID string, timeMin, timeMax time.Time, query string) ([]EventSummary, error)
- func (c *Client) QueryFreeBusy(timeMin, timeMax time.Time, calendarIDs []string) ([]FreeBusyInfo, error)
- func (c *Client) UpdateEvent(calendarID, eventID string, input EventInput) (*EventSummary, error)
- type EventInput
- type EventSummary
- type FreeBusyInfo
- type TimeRange
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 ¶
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 ¶
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 ¶
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 ¶
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
NewClientWithProvider creates a new Calendar client with OAuth2 authentication for the default account using the provided token provider
func (*Client) CreateEvent ¶
func (c *Client) CreateEvent(calendarID string, input EventInput) (*EventSummary, error)
CreateEvent creates a new calendar event
func (*Client) DeleteEvent ¶
DeleteEvent deletes a calendar event
func (*Client) ExtractGoogleDocsLinks ¶
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 (*Client) GetGoogleMeetLink ¶
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 ¶
FreeBusyInfo represents availability information for a calendar