merkliste

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidUserID indicates that the requested user ID is formatted
	// incorrectly or does not exist.
	ErrInvalidUserID = errors.New("invalid user id")
	// ErrInvalidEventID indicates that the requested event ID is formatted
	// incorrectly or does not exist.
	ErrInvalidEventID = errors.New("invalid event id")
	// ErrNoEvents indicates that an ics URL did return an empty calendar.
	ErrNoEvents = errors.New("invalid ics file (no events)")
	// ErrMultipleEvents indicates that an ics URL did return multiple events
	// instead of a single one.
	ErrMultipleEvents = errors.New("invalid ics file (multiple events)")
)
View Source
var ErrorLogger = log.New(os.Stdout, "", log.LstdFlags)

The ErrorLogger is used to log errors.

Functions

func GetCalendar

func GetCalendar(ctx context.Context, userID string, productID string, name string) (*ics.Calendar, error)

GetCalendar creates an iCal calendar with all events from the merkliste of the user with the specified ID.

For a cached variant of this method see CachedMerkliste.

func GetICSEvent

func GetICSEvent(ctx context.Context, event *ElphiEvent) (*ics.VEvent, error)

GetICSEvent fetches the iCal event for the specified event.

For a cached variant of this method see CachedMerkliste.

func GetMerkliste

func GetMerkliste(ctx context.Context, userID string) ([]string, error)

GetMerkliste returns the merkliste (favorites list) of the user with the specified ID. This function returns a list of event IDs.

Types

type CachedMerkliste

type CachedMerkliste struct {
	TTL        time.Duration
	EventCache *ttlcache.Cache[string, *ElphiEvent]
	ICSCache   *ttlcache.Cache[string, *ics.VEvent]
	ProductID  string
	Name       string
}

A CachedMerkliste provides a convenient interface to perform cached lookup of events on the Elbphilharmonie API.

func NewCachedMerkliste

func NewCachedMerkliste(ttl time.Duration) *CachedMerkliste

NewCachedMerkliste creates a new CachedMerkliste with the specified cache TTL.

func (*CachedMerkliste) GetCalendar

func (m *CachedMerkliste) GetCalendar(ctx context.Context, userID string) (*ics.Calendar, error)

GetCalendar creates an iCal calendar with the merkliste events of the specified user. This works similarly to the GetCalendar function.

func (*CachedMerkliste) GetElphiEvent

func (m *CachedMerkliste) GetElphiEvent(ctx context.Context, eventID string) (*ElphiEvent, error)

GetElphiEvent performs a cached request for the specified event. Behind the scenes this method uses the GetElphiEvent function.

func (*CachedMerkliste) GetICSEvent

func (m *CachedMerkliste) GetICSEvent(ctx context.Context, event *ElphiEvent) (*ics.VEvent, error)

GetICSEvent performs a cached request for the specified ICS file. Behind the scenes this method uses the GetICSEvent function.

func (*CachedMerkliste) RegisterMetrics

func (m *CachedMerkliste) RegisterMetrics(variableLabels []string, staticLabels prometheus.Labels)

RegisterMetrics adds caching metrics to the global prometheus registry.

func (*CachedMerkliste) StartCacheExpiration

func (m *CachedMerkliste) StartCacheExpiration()

StartCacheExpiration begins the automatic cache expiration.

func (*CachedMerkliste) StopCacheExpiration

func (m *CachedMerkliste) StopCacheExpiration()

StopCacheExpiration stops the automatic cache expiration.

type CalendarHandler

type CalendarHandler struct {
	Prefix    string
	Merkliste *CachedMerkliste
}

CalendarHandler provides an HTTP endpoint for the merkliste calendar. This implements http.Handler.

func (*CalendarHandler) ServeHTTP

func (h *CalendarHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements an iCal HTTP endpoint providing events from a merkliste.

type ElphiEvent

type ElphiEvent struct {
	ID               string `json:"evis_id"`
	Title            string `json:"title_de"`
	Subtitle         string `json:"subtitle_de"`
	Description      string `json:"description_long_de"`
	Room             string `json:"room_dispname"`
	ImageURL         string `json:"image_url"`
	ImageCopyright   string `json:"image_copyright_de"`
	WebsiteURL       string `json:"website_url"`
	StartDate        string `json:"date_start"`
	EndDate          string `json:"date_end"`
	ModificationDate string `json:"modified_at"`
	URL              string `json:"url"`
	HTML             string `json:"item_html"`
}

ElphiEvent corresponds to an event as returned by the Elbphilharmonie REST API.

func GetElphiEvent

func GetElphiEvent(ctx context.Context, eventID string) (*ElphiEvent, error)

GetElphiEvent fetches the event with the specified ID from the Elbphilharmonie API.

For a cached variant of this method see CachedMerkliste.

type EventHandler

type EventHandler struct {
	Prefix    string
	Merkliste *CachedMerkliste
}

EventHandler provides an HTTP endpoint for a calendar containing a single event. This implements http.Handler.

func (*EventHandler) ServeHTTP

func (h *EventHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements an iCal HTTP endpoint providing single Elphi events.

Jump to

Keyboard shortcuts

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