pizza

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 28 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
)
View Source
const (
	UserCacheExpire = 1 * 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 Patch001 added in v0.8.1

func Patch001(a *SQLAccessor) error

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)
	DoesFridayExist(date time.Time) (bool, error)
	AddFriday(date time.Time) error
	AddFriend(email, name string) error
	ListFriends() ([]Friend, error)
	ListFridays() ([]Friday, error)
	RemoveFriend(email string) error
	RemoveFriday(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"`
	OAuth2          OAuth2Config
}

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) AddFriend added in v0.7.2

func (c *FaunaClient) AddFriend(email, name string) 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) DoesFridayExist added in v0.8.1

func (c *FaunaClient) DoesFridayExist(date time.Time) (bool, 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)

func (*FaunaClient) ListFridays added in v0.7.3

func (c *FaunaClient) ListFridays() ([]Friday, error)

func (*FaunaClient) ListFriends added in v0.7.3

func (c *FaunaClient) ListFriends() ([]Friend, error)

func (*FaunaClient) RemoveFriday added in v0.7.3

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

func (*FaunaClient) RemoveFriend added in v0.7.3

func (c *FaunaClient) RemoveFriend(email string) error

type Friday added in v0.7.3

type Friday struct {
	Date time.Time
}

type Friend added in v0.7.3

type Friend struct {
	Email string
	Name  string
}

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 Group added in v0.8.1

type Group struct {
}

type IndexFridayData

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

type Keycloak added in v0.8.1

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

func NewKeycloak added in v0.8.1

func NewKeycloak(config OAuth2Config) (*Keycloak, error)

type MetricsRegistry

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

type OAuth2Config added in v0.8.0

type OAuth2Config struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
	KeycloakURL  string
	Realm        string
}

type PageData

type PageData struct {
	FridayTimes []IndexFridayData
	Name        string
	LoggedIn    bool
	LogoutURL   string
}

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) DoesFridayExist added in v0.8.1

func (a *SQLAccessor) DoesFridayExist(date time.Time) (bool, 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)

func (*SQLAccessor) ListFridays added in v0.7.3

func (a *SQLAccessor) ListFridays() ([]Friday, error)

func (*SQLAccessor) ListFriends added in v0.7.3

func (a *SQLAccessor) ListFriends() ([]Friend, error)

func (*SQLAccessor) RemoveFriday added in v0.7.3

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

func (*SQLAccessor) RemoveFriend added in v0.7.3

func (a *SQLAccessor) RemoveFriend(email string) 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) HandleAdmin added in v0.8.1

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

func (*Server) HandleAdminSubmit added in v0.8.1

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

func (*Server) HandleIndex

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

func (*Server) HandleLogin added in v0.8.0

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

func (*Server) HandleLoginCallback added in v0.8.0

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

func (*Server) HandleLogout added in v0.8.0

func (s *Server) HandleLogout(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 TokenClaims added in v0.8.0

type TokenClaims struct {
	Exp               int64    `json:"exp"`
	Iat               int64    `json:"iat"`
	AuthTime          int64    `json:"auth_time"`
	Jti               string   `json:"jti"`
	Iss               string   `json:"iss"`
	Aud               string   `json:"aud"`
	Sub               string   `json:"sub"`
	Typ               string   `json:"typ"`
	Azp               string   `json:"azp"`
	SessionState      string   `json:"session_state"`
	At_hash           string   `json:"at_hash"`
	Acr               string   `json:"acr"`
	Sid               string   `json:"sid"`
	EmailVerified     bool     `json:"email_verified"`
	Name              string   `json:"name"`
	PreferredUsername string   `json:"preferred_username"`
	GivenName         string   `json:"given_name"`
	FamilyName        string   `json:"family_name"`
	Email             string   `json:"email"`
	Groups            []string `json:"groups"`
	Roles             []string `json:"roles"`
}

func (*TokenClaims) HasRole added in v0.8.1

func (c *TokenClaims) HasRole(role string) bool

type User added in v0.8.1

type User struct {
	ID         string
	Username   string
	Enabled    bool
	FirstName  string
	LastName   string
	Email      string
	Attributes map[string][]string
}

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