Documentation ¶
Index ¶
- Constants
- Variables
- func A1ColumnDecodeHook(from reflect.Type, to reflect.Type, value any) (any, error)
- type A1Column
- type Columns
- type Config
- type DateSerial
- type DateSerialConverter
- type Event
- func (e Event) CalendarEventId() string
- func (e Event) Description() string
- func (e Event) DiscordEventId() string
- func (e Event) End() *time.Time
- func (e *Event) HasErrors() bool
- func (e Event) IsFullDay() bool
- func (e Event) IsInThePast() bool
- func (e Event) Location() string
- func (e Event) LogValue() slog.Value
- func (e *Event) ReportError(err error)
- func (e *Event) SetCalendarEventId(id string)
- func (e *Event) SetDiscordEventId(id string)
- func (e Event) Start() *time.Time
- func (e Event) Title() string
- func (e *Event) Updated() bool
- type EventFilterDef
- type Filter
- type Repository
- type ValueFilterDef
Constants ¶
const ( // FIELD_KEY_ are used in field mapping // They must map the eventDTO field names. FIELD_KEY_START = "start" FIELD_KEY_END = "end" FIELD_KEY_TITLE = "title" FIELD_KEY_DESCRIPTION = "description" FIELD_KEY_LOCATION = "location" FIELD_KEY_LAST_UPDATED = "lastupdated" FIELD_KEY_LAST_CHECKED = "lastchecked" FIELD_KEY_LAST_RESULT = "lastresult" FIELD_KEY_DISCORD_EVENT_ID = "discordeventid" FIELD_KEY_CALENDAR_EVENT_ID = "calendareventid" )
Variables ¶
var ErrEmptyEvent = errors.New("empty event")
ErrEmptyEvent indicates an event with no field
var ErrEmptyFilter = errors.New("should contain one of 'equalsto', 'startswith', 'notequalsto', 'and' or 'or'")
var ErrFilteredOut = errors.New("rejected by filters")
ErrFilteredOut indicates the event has not fulfilled filter conditions.
var ErrIncompleteEvent = errors.New("incomplete event")
ErrIncompleteEvent signals that the event definitions lacks some mandatory fields.
var ErrInvalidA1Column = errors.New("invalid A1 column")
Functions ¶
Types ¶
type A1Column ¶
type A1Column struct {
// contains filtered or unexported fields
}
A1Column is a column reference represented in the A1 notation
func MustParseA1Column ¶
MustParseA1Column parses a column definition. It panics if the value is invalud.
func (A1Column) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*A1Column) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Columns ¶
type Columns struct { Title *A1Column `validate:"required"` Description *A1Column `validate:"required"` Location *A1Column `validate:"required"` Start *A1Column `validate:"required"` End *A1Column `validate:"required"` CalendarEventId *A1Column `validate:"required"` DiscordEventId *A1Column `validate:"required"` LastChecked *A1Column LastUpdated *A1Column LastResult *A1Column CustomFields map[string]A1Column `mapstructure:",remain"` }
Columns maps field names to column indices. As indices are zero-based, pointer are used so that missing mappings shows as nil.
type Config ¶
type Config struct { // SpreadsheetId is the spreadsheet identifier SpreadsheetId string `mapstructure:"id" validate:"required"` // SheetTitle is the title of sheet of the spreadsheet that contains the event definitions. SheetTitle string `mapstructure:"sheet" validate:"required"` // StartingRow indicates at which row (1-based) to start looking for event definitions. // It defaults to 1 (first row of the sheet). StartingRow uint `validate:"omitempty,min=1"` // EndingRow indicates at which row (1-based) to stop looking for event definitions. // It defaults to 100. EndingRow uint `validate:"omitempty,min=1,gtfield=StartingRow"` // Columns maps field names to column indices inside the named range. Columns Columns `validate:"required"` // Filters defines conditions to select which events should be processed. Filters EventFilterDef }
Config holds the configuration to read and update the spreadsheet that contains the event definitions.
func (Config) NewRepository ¶
NewRepository creates a Repository from the configuration, using the serviceAccountFile for authentication. It validates the configuration and checks if the spreadsheet and named ranges are available.
type DateSerial ¶
type DateSerial = float64
A DateSerial represents a wallclock timestamp by a real number of days since 1899-12-30 00:00:00. This is how Google API handles timestamp .
type DateSerialConverter ¶
A DateSerialConverter helps converting between time.Time and DateSerial in a given location.
func NewDateSerialConverter ¶
func NewDateSerialConverter(location *time.Location) *DateSerialConverter
NewDateSerialConverter creates a new DateSerialConverter with the given Location.
func (*DateSerialConverter) FromTime ¶
func (c *DateSerialConverter) FromTime(value time.Time) DateSerial
IntoTime converts a DateSerial into a time.Time in the target time zone.
func (*DateSerialConverter) IntoTime ¶
func (c *DateSerialConverter) IntoTime(value DateSerial) time.Time
IntoTime converts a DateSerial into a time.Time in the target time zone.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
An Event describes an scheduled event.
func (Event) CalendarEventId ¶
func (Event) Description ¶
func (Event) DiscordEventId ¶
func (Event) IsInThePast ¶
func (*Event) ReportError ¶
func (*Event) SetCalendarEventId ¶
func (*Event) SetDiscordEventId ¶
type EventFilterDef ¶
type EventFilterDef map[string]ValueFilterDef
EventFilterDef defines a set of condition to apply on the fields of an event.
func (EventFilterDef) Create ¶
func (d EventFilterDef) Create() (Filter, error)
type Filter ¶
type Filter interface { // Accept must returns an error whenever the value is rejecteds. Accept(value any) error }
A Filter indicates whether a value should be accepted.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository allows to read and to update events from and to the spreadsheet.
func (*Repository) ReadEvents ¶
func (r *Repository) ReadEvents() ([]Event, error)
ReadEvents extract all events from the designated named zone of the spreadsheets. Each row is read in turn, mapped into an event and validated. Incomplete events are ignored.
func (*Repository) UpdateEvent ¶
func (r *Repository) UpdateEvent(event *Event) error
UpdateEvent stores the Discord scheduled event identifier of the given event into the spreadsheet. It also updates the metadata fields LastChecked, LastUpdated and LastResult if they are mapped.
type ValueFilterDef ¶
type ValueFilterDef struct { EqualsTo *any NotEqualsTo *any StartsWith *string `validate:"omitempty,min=1"` And []ValueFilterDef `validate:"omitempty,min=1"` Or []ValueFilterDef `validate:"omitempty,min=1"` }
ValueFilterDef defines a condition on a single value.
func (ValueFilterDef) Create ¶
func (d ValueFilterDef) Create() (Filter, error)