Documentation ¶
Index ¶
- func MakeHTTPHandler(s sseServer, log logger) http.Handler
- func TranslateEventsToSSEChannel(sse sseService) events.Listener
- type Event
- type EventData
- type MemStorage
- func (s *MemStorage) Add(channelID string, event Event) error
- func (s *MemStorage) Delete(channelID string, event Event) error
- func (s *MemStorage) GC(eventMaxAge, gcPeriod string, wg *sync.WaitGroup) error
- func (s *MemStorage) GetAllInChannel(channelID string) []Event
- func (s *MemStorage) GetByLastID(channelID string, lastEventID int64) []Event
- type Service
- func (s *Service) DumpStorage(channelID string) []Event
- func (s *Service) PubEvent(channelID string, data EventData, ttl int64) error
- func (s *Service) SubscribeToChannel(channelID, lastEventID string) (chan interface{}, []Event, error)
- func (s *Service) Unsubscribe(channelID string, listener chan interface{}) error
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeHTTPHandler ¶
MakeHTTPHandler returns a handler that makes a set of endpoints available on predefined paths.
func TranslateEventsToSSEChannel ¶
TranslateEventsToSSEChannel translates the events from the events package to the webhook events.
Types ¶
type Event ¶
Event struct
func (Event) MapToSseEvent ¶
MapToSseEvent func to convert struct Event to sse.Event
type EventData ¶
type EventData struct { Name string `json:"name"` Payload interface{} `json:"payload"` }
EventData struct
type MemStorage ¶
MemStorage struct
func NewMemStorage ¶
func NewMemStorage() *MemStorage
NewMemStorage is a factory func, returns a new instance of the MemStorage structure
func (*MemStorage) Add ¶
func (s *MemStorage) Add(channelID string, event Event) error
Add event to storage
func (*MemStorage) Delete ¶
func (s *MemStorage) Delete(channelID string, event Event) error
Delete event from storage
func (*MemStorage) GC ¶
func (s *MemStorage) GC(eventMaxAge, gcPeriod string, wg *sync.WaitGroup) error
GC - garbage collector
func (*MemStorage) GetAllInChannel ¶
func (s *MemStorage) GetAllInChannel(channelID string) []Event
GetAllInChannel returns all events in channel
func (*MemStorage) GetByLastID ¶
func (s *MemStorage) GetByLastID(channelID string, lastEventID int64) []Event
GetByLastID returns events in a channel which has id greater than given one
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
SSE service struct
func NewService ¶
NewService factory func returns new SSE service
func (*Service) DumpStorage ¶
DumpStorage func returns all events in channel
func (*Service) PubEvent ¶
PubEvent func publishes data to channel with given ttl in seconds, returns error if any
func (*Service) SubscribeToChannel ¶
func (s *Service) SubscribeToChannel(channelID, lastEventID string) (chan interface{}, []Event, error)
SubscribeToChannel func returns channel with events and history of events, returns error if any
func (*Service) Unsubscribe ¶
Unsubscribe from channel with given listener returns error if any
type Storage ¶
type Storage interface { // get all events in channel GetAllInChannel(channelID string) []Event // get events in a channel which has id greater than given one GetByLastID(channelID string, lastEventID int64) []Event // Add event to storage Add(channelID string, event Event) error // Delete event from storage Delete(channelID string, event Event) error // Deletes event which is older then given time from channel GC(eventMaxAge, gcPeriod string, wg *sync.WaitGroup) error }
Storage interface