core

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: AGPL-3.0 Imports: 25 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"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Calendar

type Calendar struct {
	Repository    *gogit.Repository
	Tags          []string
	EncryptionKey []byte
}

func (*Calendar) IsEncrypted

func (cal *Calendar) IsEncrypted() bool

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) AddRemote

func (c *Core) AddRemote(calendar, remoteName, remoteUrl string) error

Adds a new remote to the specified calendar repository.

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) 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() []string

Returns a list of calendar names loaded.

func (*Core) LoadCalendars

func (c *Core) LoadCalendars() error

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

func (*Core) PullAll

func (c *Core) PullAll() error

Update all repositories from remotes.

func (*Core) PushAll

func (c *Core) PushAll() error

Update all repotes for all repositories.

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) SetCorsProxy

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

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

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) 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"`
}

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 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