core

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IndexFileName     string = "index.json"
	RichIndexFileName string = "index-rich.json"

	EventsDirName string = "events"

	GitAuthorName string = "git-calendar"
	GitRemoteName string = "origin"
	GitBranchName string = "main"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CalendarInfo added in v0.1.3

type CalendarInfo struct {
	Name      string `json:"name"`
	Tags      []Tag  `json:"tags,omitempty"`
	Encrypted bool   `json:"encrypted"`
	RemoteUrl string `json:"remote_url,omitempty"`
}

A DTO like calendar struct.

type Core

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

The real API.

Works with raw Go structs, use api.Api to work with JSON.

func NewCore

func NewCore() *Core

A "constructor" for Core.

func (*Core) CloneCalendar

func (c *Core) CloneCalendar(repoUrl *url.URL, password string) error

Clones a repository/calendar from url, using CORS proxy, if specified.

func (*Core) CreateCalendar

func (c *Core) CreateCalendar(name, password string) error

Creates a new calendar.

func (*Core) CreateEvent

func (c *Core) CreateEvent(event Event) (*Event, error)

Creates a new event and save it into git.

func (*Core) ExportZip added in v0.1.2

func (c *Core) ExportZip(calendar string) ([]byte, error)

func (*Core) GetEvent

func (c *Core) GetEvent(id uuid.UUID) (*Event, error)

Returns event by id, or an error if it doesn't exist.

func (*Core) GetEvents

func (c *Core) GetEvents(from, to time.Time) []Event

Returns an array of events which fall into the specified interval [from, to].

func (*Core) ListCalendars

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

ListCalendars returns calendar metadata.

func (*Core) LoadCalendars

func (c *Core) LoadCalendars() error

Tries to load every directory/repo/calendar in the fs root.

func (*Core) RemoveCalendar

func (c *Core) RemoveCalendar(name string) error

Removes and deletes the whole calendar.

func (*Core) RemoveEvent

func (c *Core) RemoveEvent(event Event) error

Removes a real (basic/parent) event from the calendar. Use RemoveRepeatingEvent method for repeating events.

func (*Core) RemoveRepeatingEvent

func (c *Core) RemoveRepeatingEvent(event Event, strat UpdateStrategy) error

Removes a child event by adding an exception to its parent repeat rule.

func (*Core) RenameCalendar added in v0.1.3

func (c *Core) RenameCalendar(oldName, newName string) error

func (*Core) SetCorsProxy

func (c *Core) SetCorsProxy(proxyUrl string) error

Sets a url for CORS proxy. This is only needed inside a browser.

func (*Core) SyncAll added in v0.1.4

func (c *Core) SyncAll() error

SyncAll tries to synchronize all calendars with its remotes.

func (*Core) UpdateEvent

func (c *Core) UpdateEvent(event Event) (*Event, error)

Updates a Basic event based on its id. Use UpdateRepeatingEvent method for repeating events.

func (*Core) UpdateRemote added in v0.1.4

func (c *Core) UpdateRemote(calendar string, remoteURL *url.URL) error

func (*Core) UpdateRepeatingEvent

func (c *Core) UpdateRepeatingEvent(old, new Event, strat UpdateStrategy) (*Event, error)

Removes a child event by adding an exception to its parent repeat rule.

type Event

type Event struct {
	Id          uuid.UUID   `json:"id,omitzero"`       // Should not change (different id = different event). Only UUIDv4 or UUIDv8 (for children) is being used.
	Title       string      `json:"title,omitzero"`    // Should not be empty.
	Location    string      `json:"location,omitzero"` // Physical or virtual location (e.g., URL).
	Description string      `json:"description,omitzero"`
	From        time.Time   `json:"from,omitzero"`
	To          time.Time   `json:"to,omitzero"`
	Calendar    string      `json:"calendar,omitzero"`  // The name of the calendar the event belongs to.
	Tag         string      `json:"tag,omitzero"`       // User-defined category or label.
	ParentId    uuid.UUID   `json:"parent_id,omitzero"` // Specific for child events. It is uuid.Nil if the event is basic or parent.
	Repeat      *Repetition `json:"repeat,omitzero"`
	UpdatedAt   time.Time   `json:"updated_at,omitzero"` // Used for git conflict resolution; latest wins.
}

Event represents a single calendar entry.

Can be one of these:

  1. Basic: A standalone event that does not repeat (ParentId is nil, Repeat is nil).
  2. Parent: The "source of truth" for a recurring series (ParentId is nil, Repeat defines the rule).
  3. Child: A generated occurrence from a Parent (ParentId points to its Parent, Repeat copies the Parent rule).

func (Event) IsBasic

func (e Event) IsBasic() bool

func (Event) IsChild

func (e Event) IsChild() bool

func (Event) IsParent

func (e Event) IsParent() bool

func (*Event) LoadFromFile

func (e *Event) LoadFromFile(file billy.File, decryptionKey []byte) error

func (*Event) Validate

func (e *Event) Validate() error

func (Event) WriteToFile

func (e Event) WriteToFile(file billy.File, key []byte) error

type Freq

type Freq int

Repeating frequency.

const (
	Invalid Freq = iota // ints default value 0 is invalid
	Day                 // Repeat daily.
	Week                // Repeat weekly.
	Month               // Repeat monthly.
	Year                // Repeat yearly.

)

func (Freq) IsValid

func (t Freq) IsValid() bool

type IntervalTree

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

func NewIntervalTree

func NewIntervalTree() *IntervalTree

func (*IntervalTree) InsertEvent

func (et *IntervalTree) InsertEvent(event Event) error

Inserts an Event to its interval in the tree.

func (*IntervalTree) RemoveEvent

func (et *IntervalTree) RemoveEvent(event Event) error

Deletes an Event from the interval tree.

type Repetition

type Repetition struct {
	Frequency  Freq        `json:"frequency,omitzero"`  // The unit of time for recurrence (Day, Week, Month, etc.).
	Interval   int         `json:"interval,omitzero"`   // The multiplier for Frequency (e.g., Interval:2 * Frequency:Week = every other week).
	Until      time.Time   `json:"until,omitzero"`      // Hard stop date for the series. (Inclusive: occurrences starting BEFORE or even ON this time are included.)
	Count      int         `json:"count,omitzero"`      // Total number of occurrences to generate.
	Exceptions []uuid.UUID `json:"exceptions,omitzero"` // List of Child IDs that deviate from the base rule (edited or cancelled).
}

Repetition defines the recurrence rules for a Parent event.

A Repetition object exists only on Parent events to generate Children. A series must be capped by either Until (date) or Count (occurrences). Not both.

func (*Repetition) Validate

func (r *Repetition) Validate() error

type Tag added in v0.1.3

type Tag struct {
	Name  string `json:"name,omitzero"`
	Color string `json:"color,omitzero"`
}

type UpdateStrategy

type UpdateStrategy int
const (
	Current UpdateStrategy = iota
	Following
	All
)

func (UpdateStrategy) IsValid

func (opt UpdateStrategy) IsValid() bool

Jump to

Keyboard shortcuts

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