Documentation
¶
Overview ¶
The countdown package provides a simple service for managing countdown timers.
Index ¶
- Constants
- type BoltStore
- type Options
- type Service
- func (s *Service) CancelTimer(id int) error
- func (s *Service) GetTimer(id int) (*Timer, error)
- func (s *Service) PauseTimer(id int) error
- func (s *Service) ResumeTimer(id int) error
- func (s *Service) Start(store Store, options *Options) error
- func (s *Service) StartTimer(id, duration int) (*Timer, error)
- type Store
- type Timer
- type TimerExistsError
- type TimerNotFoundError
Constants ¶
const ( Running string = "running" Paused string = "paused" Cancelled string = "cancelled" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoltStore ¶
func ConnectBoltStore ¶
func (BoltStore) ListTimers ¶
func (BoltStore) RemoveTimer ¶
func (BoltStore) UpdateTimer ¶
type Service ¶
type Service struct {
// Store options for running the Service
Options *Options
// contains filtered or unexported fields
}
The primary entry point for this library. It is responsible for maintaining the Timers and interacting with the client.
func (*Service) CancelTimer ¶
CancelTimer cancels an existing Timer if it exists.
func (*Service) GetTimer ¶
GetTimer retrieves an existing Timer. First it checks if there is a Timer in memory. Then it checks the DB, and if it finds one there, it sets up a new one because the old channels are gone.
func (*Service) PauseTimer ¶
PauseTimer temporarily pauses a Timer if it exists.
func (*Service) ResumeTimer ¶
ResumeTimer temporarily pauses a Timer if it exists.
type Store ¶
type Store interface {
// ListTimers returns all timers
ListTimers() []*Timer
// AddTimer adds a new Timer to the store
AddTimer(timer *Timer) error
// GetTimer gets a timer by id
GetTimer(id int) (*Timer, error)
// UpdateTimer updates an existing Timer
UpdateTimer(timer *Timer) error
// Remove removes a Timer from the store
RemoveTimer(id int) error
}
General interface for storing Timer info. This allows for multiple backend implementations.
type Timer ¶
type Timer struct {
// A unique identifier
Id int `json:"id"`
// How long it should run
Duration int `json:"duration"`
// contains filtered or unexported fields
}
The timer can be expressed as a channel of Messages. The client will read from this channel to get updated time, and will send messages to it.
type TimerExistsError ¶
type TimerExistsError struct{}
func (TimerExistsError) Error ¶
func (e TimerExistsError) Error() string
type TimerNotFoundError ¶
type TimerNotFoundError struct{}
func (TimerNotFoundError) Error ¶
func (e TimerNotFoundError) Error() string