pizza

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGoogleCalendarTimeout  = 5 * time.Second
	DefaultGoogleCalendarTimezone = "America/New_York"
)
View Source
const (
	GmailSMTPServer = ""
	GmailSMTPPort   = 800
)
View Source
const (
	DefaultFridayCacheTTL         = 1 * time.Hour
	DefaultFriendNameCacheTTL     = 24 * time.Hour
	DefaultNegativeFriendCacheTTL = 5 * time.Minute
)

Variables

View Source
var (
	ErrEventNotFound = errors.New("event not found")
)
View Source
var EventDuration = time.Hour * 4
View Source
var GMAIL_API_KEY string

Functions

func Edit

func Edit(args []string)

func Patch

func Patch(args []string)

func Run

func Run(args []string)

func SendConfirmationEmail

func SendConfirmationEmail(email, code string) error

Types

type Accessor

type Accessor interface {
	CreateTables() error
	IsFriendAllowed(email string) (bool, error)
	GetFriendName(email string) (string, error)
	GetUpcomingFridays(daysAhead int) ([]time.Time, error)
	GetUpcomingFridaysAfter(after time.Time, daysAhead int) ([]time.Time, error)
	AddFriday(date time.Time) error
}

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[T any](ttl time.Duration, refreshFunc func(key string) (T, error)) Cache[T]

func NewCache2

func NewCache2[T any](ttl time.Duration, refreshFunc func(key string) (T, error)) *Cache[T]

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string) (T, error)

func (*Cache[T]) Has

func (c *Cache[T]) Has(key string) bool

func (*Cache[T]) Store

func (c *Cache[T]) Store(key string, val T)

type CacheValue

type CacheValue[V any] struct {
	// contains filtered or unexported fields
}

type Calendar

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

func NewCalendar

func NewCalendar(source CalendarSource) *Calendar

func (*Calendar) ActivateEvent

func (c *Calendar) ActivateEvent(eventID string) error

func (*Calendar) CancelEvent

func (c *Calendar) CancelEvent(eventID string) error

func (*Calendar) CreateEvent

func (c *Calendar) CreateEvent(newEvent CalendarEvent) error

func (*Calendar) GetEvent

func (c *Calendar) GetEvent(eventID string) (CalendarEvent, error)

func (*Calendar) InviteToEvent

func (c *Calendar) InviteToEvent(eventID, email, name string) error

func (*Calendar) ListEvents

func (c *Calendar) ListEvents(numEvents int) ([]CalendarEvent, error)

func (*Calendar) ListEventsBetween

func (c *Calendar) ListEventsBetween(start, end time.Time, numEvents int) ([]CalendarEvent, error)

type CalendarConfig

type CalendarConfig struct {
	CredentialFile string `yaml:"credentialFile"`
	TokenFile      string `yaml:"tokenFile"`
	ID             string `yaml:"id"`
}

type CalendarEvent

type CalendarEvent struct {
	AnyoneCanAddSelf      bool
	Attendees             []string
	Description           string
	EndTime               time.Time
	GuestsCanInviteOthers bool
	GuestsCanModify       bool
	Id                    string
	Locked                bool
	StartTime             time.Time
	Status                string
	Summary               string
	Visibility            string
}

type CalendarSource

type CalendarSource interface {
	CreateEvent(CalendarEvent) error
	GetEvent(eventID string) (CalendarEvent, error)
	InviteToEvent(eventID, email, name string) error
	ListEvents(numEvents int) ([]CalendarEvent, error)
	ListEventsBetween(start, end time.Time, numEvents int) ([]CalendarEvent, error)
	CancelEvent(eventID string) error
	ActivateEvent(eventID string) error
}

type Config

type Config struct {
	Port            int            `yaml:"port"`
	StaticDir       string         `yaml:"staticDir"`
	ReadTimeout     time.Duration  `yaml:"readTimeout"`
	WriteTimeout    time.Duration  `yaml:"writeTimeout"`
	ShutdownTimeout time.Duration  `yaml:"shutdownTimeout"`
	Calendar        CalendarConfig `yaml:"calendar"`
	MetricsPort     int            `yaml:"metricsPort"`
	FaunaSecret     string         `yaml:"faunaSecret"`
	UseSQLite       bool           `yaml:"useSQLite"`
	DBFile          string         `yaml:"dbFile"`
}

func LoadConfig

func LoadConfig(filename string) (Config, error)

func LoadConfigEnv

func LoadConfigEnv() Config

type CounterMetric

type CounterMetric interface {
	Increment()
}

type FaunaClient

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

func NewFaunaClient

func NewFaunaClient(secret string) *FaunaClient

func (*FaunaClient) AddFriday

func (c *FaunaClient) AddFriday(date time.Time) error

func (*FaunaClient) ConfirmRSVP

func (c *FaunaClient) ConfirmRSVP(friendEmail, code string) error

func (*FaunaClient) CreateRSVP

func (c *FaunaClient) CreateRSVP(friendEmail, code string, pendingDates []time.Time) error

func (*FaunaClient) CreateTables

func (c *FaunaClient) CreateTables() error

func (*FaunaClient) GetAllFridays

func (c *FaunaClient) GetAllFridays() ([]time.Time, error)

func (*FaunaClient) GetFriendName

func (c *FaunaClient) GetFriendName(friendEmail string) (string, error)

func (*FaunaClient) GetUpcomingFridays

func (c *FaunaClient) GetUpcomingFridays(daysAhead int) ([]time.Time, error)

func (*FaunaClient) GetUpcomingFridaysAfter

func (c *FaunaClient) GetUpcomingFridaysAfter(after time.Time, daysAhead int) ([]time.Time, error)

func (*FaunaClient) IsFriendAllowed

func (c *FaunaClient) IsFriendAllowed(friendEmail string) (bool, error)

type GaugeMetric

type GaugeMetric interface {
	Set(float64)
}

type GoogleCalendar

type GoogleCalendar struct {
	Timezone string
	Timeout  time.Duration
	// contains filtered or unexported fields
}

func NewGoogleCalendar

func NewGoogleCalendar(credentialFile, tokenFile, id string, ctx context.Context) (*GoogleCalendar, error)

func (*GoogleCalendar) ActivateEvent

func (c *GoogleCalendar) ActivateEvent(eventID string) error

func (*GoogleCalendar) CancelEvent

func (c *GoogleCalendar) CancelEvent(eventID string) error

func (*GoogleCalendar) CreateEvent

func (c *GoogleCalendar) CreateEvent(newEvent CalendarEvent) error

func (*GoogleCalendar) GetEvent

func (c *GoogleCalendar) GetEvent(eventID string) (CalendarEvent, error)

func (*GoogleCalendar) InviteToEvent

func (c *GoogleCalendar) InviteToEvent(eventID, email, name string) error

func (*GoogleCalendar) ListEvents

func (c *GoogleCalendar) ListEvents(numEvents int) ([]CalendarEvent, error)

func (*GoogleCalendar) ListEventsBetween

func (c *GoogleCalendar) ListEventsBetween(start, end time.Time, numEvents int) ([]CalendarEvent, error)

type IndexFridayData

type IndexFridayData struct {
	Date   string
	ID     int64
	Guests []int
}

type MetricsRegistry

type MetricsRegistry interface {
	NewCounterMetric(name string, labels map[string]string) CounterMetric
	NewGaugeMetric(name string, labels map[string]string) GaugeMetric
}

type PageData

type PageData struct {
	FridayTimes []IndexFridayData
}

type PrometheusCounterMetric

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

func (*PrometheusCounterMetric) Increment

func (m *PrometheusCounterMetric) Increment()

type PrometheusGaugeMetric

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

func (*PrometheusGaugeMetric) Set

func (m *PrometheusGaugeMetric) Set(value float64)

type PrometheusRegistry

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

func NewPrometheusRegistry

func NewPrometheusRegistry() *PrometheusRegistry

func (*PrometheusRegistry) NewCounterMetric

func (reg *PrometheusRegistry) NewCounterMetric(name string, labels map[string]string) CounterMetric

func (*PrometheusRegistry) NewGaugeMetric

func (reg *PrometheusRegistry) NewGaugeMetric(name string, labels map[string]string) GaugeMetric

func (*PrometheusRegistry) Serve

func (reg *PrometheusRegistry) Serve(port int)

type SQLAccessor

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

func NewSQLAccessor

func NewSQLAccessor(dbfile string) (*SQLAccessor, error)

func (*SQLAccessor) AddFriday

func (a *SQLAccessor) AddFriday(date time.Time) error

func (*SQLAccessor) AddFriend

func (a *SQLAccessor) AddFriend(email, name string) error

func (*SQLAccessor) Close

func (a *SQLAccessor) Close()

func (*SQLAccessor) CreateTables

func (a *SQLAccessor) CreateTables() error

func (*SQLAccessor) GetFriendName

func (a *SQLAccessor) GetFriendName(email string) (string, error)

func (*SQLAccessor) GetUpcomingFridays

func (a *SQLAccessor) GetUpcomingFridays(daysAhead int) ([]time.Time, error)

func (*SQLAccessor) GetUpcomingFridaysAfter

func (a *SQLAccessor) GetUpcomingFridaysAfter(after time.Time, daysAhead int) ([]time.Time, error)

func (*SQLAccessor) IsFriendAllowed

func (a *SQLAccessor) IsFriendAllowed(email string) (bool, error)

type Server

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

func NewServer

func NewServer(config Config, metricsReg MetricsRegistry) (Server, error)

func (*Server) GetWrapped

func (s *Server) GetWrapped(year int) (WrappedData, error)

func (*Server) Handle4xx

func (s *Server) Handle4xx(w http.ResponseWriter, r *http.Request)

func (*Server) Handle500

func (s *Server) Handle500(w http.ResponseWriter, r *http.Request)

func (*Server) HandleIndex

func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request)

func (*Server) HandleSubmit

func (s *Server) HandleSubmit(w http.ResponseWriter, r *http.Request)

func (*Server) HandledWrapped

func (s *Server) HandledWrapped(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop()

func (*Server) WatchCalendar

func (s *Server) WatchCalendar(period time.Duration)

type Store

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

func NewStore

func NewStore(accessor Accessor) *Store

func (*Store) GetFriendName

func (s *Store) GetFriendName(email string) (string, error)

func (*Store) GetUpcomingFridays

func (s *Store) GetUpcomingFridays(daysAhead int) ([]time.Time, error)

func (*Store) IsFriendAllowed

func (s *Store) IsFriendAllowed(email string) (bool, error)

func (*Store) SetCacheTTL

func (s *Store) SetCacheTTL(fridayCacheTTL, friendNameCacheTTL, negativeFriendCacheTTL time.Duration)

type WrappedData

type WrappedData struct {
	Friends      map[string][]time.Time `json:"friends"`
	TotalFridays int                    `json:"totalFridays"`
}

type WrappedPageData

type WrappedPageData struct {
	Email        string
	Name         string
	Attendance   []string
	TotalFridays int
}

Jump to

Keyboard shortcuts

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