Documentation
¶
Index ¶
- Variables
- type Events
- func (e *Events) Exists(event string) bool
- func (e *Events) IsPaused(event string) bool
- func (e *Events) Len() int
- func (e *Events) Names() []string
- func (e *Events) New(event string, rules *Rules) error
- func (e *Events) Pause(event string, duration time.Duration) error
- func (e *Events) PauseTime(event string) time.Time
- func (e *Events) Remove(event string)
- func (e *Events) RuleDelAll(event, rule string)
- func (e *Events) RuleDelD(event, rule string)
- func (e *Events) RuleDelI(event, rule string)
- func (e *Events) RuleDelS(event, rule string)
- func (e *Events) RuleDelT(event, rule string)
- func (e *Events) RuleGetD(event, rule string) (time.Duration, bool)
- func (e *Events) RuleGetI(event, rule string) (int, bool)
- func (e *Events) RuleGetS(event, rule string) (string, bool)
- func (e *Events) RuleGetT(event, rule string) (time.Time, bool)
- func (e *Events) RuleSetD(event, rule string, val time.Duration)
- func (e *Events) RuleSetI(event, rule string, val int)
- func (e *Events) RuleSetS(event, rule string, val string)
- func (e *Events) RuleSetT(event, rule string, val time.Time)
- func (e *Events) UnPause(event string) error
- type Rules
- type Subscribe
- func (s *Subscribe) CreateSub(contact, api string, admin, ignore bool) *Subscriber
- func (s *Subscribe) EventRemove(event string)
- func (s *Subscribe) GetAdmins() (subs []*Subscriber)
- func (s *Subscribe) GetIgnored() (subs []*Subscriber)
- func (s *Subscribe) GetSubscriber(contact, api string) (*Subscriber, error)
- func (s *Subscribe) GetSubscribers(eventName string) (subscribers []*Subscriber)
- func (s *Subscribe) StateFileLoad() error
- func (s *Subscribe) StateFileRelocate(newPath string) (err error)
- func (s *Subscribe) StateFileSave() error
- func (s *Subscribe) StateGetJSON() (string, error)
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorSubscriberNotFound is returned any time a requested subscriber does not exist. ErrorSubscriberNotFound = errors.New("subscriber not found") // ErrorEventNotFound is returned when a requested event has not been created. ErrorEventNotFound = errors.New("event not found") // ErrorEventExists is returned when a new event with an existing name is created. ErrorEventExists = errors.New("event already exists") )
Functions ¶
This section is empty.
Types ¶
type Events ¶ added in v1.1.0
type Events struct { // Map is the events/rules map. Use the provided methods to interact with it. Map map[string]*Rules `json:"events_map"` // sync.RWMutex locks and unlocks the Events map sync.RWMutex }
Events represents the map of tracked global Events. This is an arbitrary list that can be used to filter notifications in a consuming application.
func (*Events) IsPaused ¶ added in v1.1.0
IsPaused returns true if the event's notifications are pasued. Returns true if the event subscription does not exist.
func (*Events) Pause ¶ added in v1.1.0
Pause (or unpause with 0 duration) a subscriber's event subscription. Returns an error only if the event subscription is not found.
func (*Events) RuleDelAll ¶ added in v1.1.0
RuleDelAll deletes rules of any type with a specific name.
type Rules ¶
type Rules struct { Pause time.Time `json:"pause"` D map[string]time.Duration I map[string]int S map[string]string T map[string]time.Time }
Rules contains the pause time and rules for a subscriber's event subscription. Rules are unused by the library and available for consumers.
type Subscribe ¶
type Subscribe struct { // EnableAPIs sets the allowed APIs. Only subscriptions that have an API // with a prefix in this list will return from the GetSubscribers() method. EnableAPIs []string `json:"enabled_apis"` // imessage, skype, pushover, email, slack, growl, all, any // Events stores a list of arbitrary events. Use the included methods to interact with it. // This does not affect GetSubscribers(). Use the data here as a filter in your app. Events *Events `json:"events"` // Subscribers is a list of all Subscribers. Subscribers []*Subscriber `json:"subscribers"` // contains filtered or unexported fields }
Subscribe is the data needed to initialize this module.
func (*Subscribe) CreateSub ¶
func (s *Subscribe) CreateSub(contact, api string, admin, ignore bool) *Subscriber
CreateSub creates or updates a subscriber.
func (*Subscribe) EventRemove ¶
EventRemove obliterates an event and all subsciptions for it.
func (*Subscribe) GetAdmins ¶
func (s *Subscribe) GetAdmins() (subs []*Subscriber)
GetAdmins returns a list of subscribed admins.
func (*Subscribe) GetIgnored ¶
func (s *Subscribe) GetIgnored() (subs []*Subscriber)
GetIgnored returns a list of ignored subscribers.
func (*Subscribe) GetSubscriber ¶
func (s *Subscribe) GetSubscriber(contact, api string) (*Subscriber, error)
GetSubscriber gets a subscriber based on their contact info.
func (*Subscribe) GetSubscribers ¶
func (s *Subscribe) GetSubscribers(eventName string) (subscribers []*Subscriber)
GetSubscribers returns a list of valid event subscribers. This is the main method that should be triggered when an event occurs. Call this method when your event fires, collect the subscribers and send them notifications in your app. Subscribers can be people. Or functions.
func (*Subscribe) StateFileLoad ¶
StateFileLoad data from a json file.
func (*Subscribe) StateFileRelocate ¶
StateFileRelocate writes the state file to a new location.
func (*Subscribe) StateFileSave ¶
StateFileSave writes out the state file.
func (*Subscribe) StateGetJSON ¶
StateGetJSON returns the state data in json format.
type Subscriber ¶
type Subscriber struct { // API is the type of API the subscriber is subscribed with. Used to filter results. API string `json:"api"` // Contact is the contact info used in the API to send the subscriber a notification. Contact string `json:"contact"` // Events is a list of events the subscriber is subscribed to, including a cooldown/pause time. Events *Events `json:"events"` // This is just extra data that can be used to make the user special. Admin bool `json:"is_admin"` // Ignored will exclude a user from GetSubscribers(). Ignored bool `json:"ignored"` }
Subscriber describes the contact info and subscriptions for a person.
func (*Subscriber) Subscribe ¶
func (s *Subscriber) Subscribe(event string) error
Subscribe adds an event subscription to a subscriber. Returns an error only if the event subscription already exists.