calendarapi

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package calendarapi allows using the Google Calendar API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// FetchEvents retrieves calendar events within the specified time range.
	//
	// The ctx argument allows to cancel a pending call.
	//
	// The config argument contains the configuration for fetching events.
	//
	// The return value is either a non-empty slice of [Event] or an error.
	FetchEvents(ctx context.Context, config *FetchEventsConfig) ([]Event, error)
}

Client is a Google Calendar API client.

func NewClient

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

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

The ctx argument allows to cancel a pending call.

The credentialsPath argument is the file path containing the service account credentials.

The return value is either a valid Client or an error.

Design note: This function returns the Client interface rather than a concrete type, which deviates from the Go proverb "accept interfaces, return structs." However, since this package exports behavior (calendar operations) rather than state, and consumers primarily need mockability for testing, returning the interface is appropriate here. This approach aligns with how interfaces are used in larger Go codebases where testability is a primary concern.

type Event added in v0.3.0

type Event struct {
	// Summary is the calendar event summary
	Summary string

	// StartTime is the calendar event start time
	StartTime string

	// EndTime is the calendar event end time
	EndTime string
}

Event is the kind of event emitted by this package.

It simplifies the actually-fetched event by removing unnecessary fields and making the result straightforward to parse.

func (*Event) String added in v0.3.0

func (ev *Event) String() string

type FetchEventsConfig

type FetchEventsConfig struct {
	// CalendarID is the MANDATORY calendar ID to use.
	CalendarID string

	// StartTime is the MANDATORY moment in time where to start.
	StartTime time.Time

	// EndTime is the MANDATORY moment in time where to end.
	EndTime time.Time

	// MaxEvents is the MANDATORY number of maximum events to fetch.
	MaxEvents int64
}

FetchEventsConfig contains config for [Client.FetchEvents].

Initialize all MANDATORY fields.

Jump to

Keyboard shortcuts

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