Documentation ¶
Index ¶
- func NewServer(s *Supervisor) *http.Server
- type Application
- type Channel
- type Config
- type ConfigApplication
- type ConfigError
- type ConfigRedis
- type ConnectionEstablishedData
- type DB
- func (db *DB) AddUserIDToChannel(appname string, channame string, uid int) error
- func (db *DB) DeleteUserID(appname string, uid int) error
- func (db *DB) DeleteUserIDFromChannel(appname string, channame string, uid int) error
- func (db *DB) FinishDB()
- func (db *DB) FlushDB()
- func (db *DB) GetAllUserIDs(appname string) ([]int, error)
- func (db *DB) GetChannel(appname string, channame string) (*Channel, error)
- func (db *DB) GetChannels(appname string) (map[string]*Channel, error)
- func (db *DB) GetOrCreateChannel(appname string, channame string) (*Channel, error)
- type Event
- type EventRequest
- type PusherEvent
- type Supervisor
- func (s *Supervisor) AddUser(appname string, conn *websocket.Conn) (*User, error)
- func (s *Supervisor) Broadcast(a *Application, e *Event, cn string) error
- func (s *Supervisor) Finish()
- func (s *Supervisor) GetApp(name string) (*Application, error)
- func (s *Supervisor) GetAppFromKey(key string) (*Application, error)
- func (s *Supervisor) GetChannel(appname string, channame string) (*Channel, error)
- func (s *Supervisor) GetChannels(appname string) (map[string]*Channel, error)
- func (s *Supervisor) GetOrCreateChannel(appname string, channame string) (*Channel, error)
- func (s *Supervisor) InitApps()
- func (s *Supervisor) KickRedisSubscription()
- func (s *Supervisor) PublishRedisEvent(ev *EventRequest) error
- func (s *Supervisor) RemoveUser(appname string, uid int) error
- func (s *Supervisor) Subscribe(appname string, uid int, channame string) error
- func (s *Supervisor) Unsubscribe(appname string, uid int, channame string) error
- type UIDArray
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
func NewServer(s *Supervisor) *http.Server
NewServer creates a new HTTP server for MicroNotifier.
Types ¶
type Application ¶
type Application struct { Name string Channels map[string]*Channel Users mapset.Set // Set of User }
Application is a namaspece for channels
func (*Application) GetUserByID ¶
func (a *Application) GetUserByID(ID int) *User
GetUserByID returns a user with the given ID, or nil. (NB: Expect nil return value, for the user may not be managed by this process.)
type Channel ¶
Channel corresponds to Pusher channel. Channels are implicitly created when subscribed and/or triggered.
func (*Channel) SubscribeUser ¶
SubscribeUser let the user of uid subscribe the channel. Returns the number of subscribers of the channel.
func (*Channel) SubscriptionCount ¶
SubscriptionCount returns the number of subscriptions of the channel. A user can subscribe the same channel multiple times, so the count can be greater than UserCount.
func (*Channel) UnsubscribeUser ¶
UnsubscribeUser let the user of uid unsubscribe the channel. Returns the updated number of subscribers of the channel.
type Config ¶
type Config struct { Host string `json:"host"` Port int `json:"port"` Certificate string `json:"certificate"` PrivateKey string `json:"private-key"` Redis ConfigRedis `json:"redis"` Applications []ConfigApplication `json:"applications"` }
Config holds the enture configuration parameters.
func ReadConfig ¶
ReadConfig reads configuration data and returns Config struct or an error.
func ReadConfigFile ¶
ReadConfigFile reads a config file and returns Config struct or an error.
func (*Config) GetApp ¶
func (c *Config) GetApp(name string) *ConfigApplication
GetApp extracts ConfigApplication of the named application, or nil if no such application is defined in the config.
func (*Config) GetAppFromKey ¶
func (c *Config) GetAppFromKey(key string) *ConfigApplication
GetAppFromKey extracts ConfigApplication of the application with given key, or nil if no such application is defined in the config.
type ConfigApplication ¶
type ConfigApplication struct { Name string `json:"name"` Key string `json:"key"` Secret string `json:"secret"` }
ConfigApplication is the configuration of individual applications.
type ConfigError ¶
type ConfigError struct {
// contains filtered or unexported fields
}
ConfigError will be returned when something bad occur during reading config file.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
type ConfigRedis ¶
type ConfigRedis struct { Address string `json:"address"` Database int `json:"database"` Password string `json:"password"` Sentinel bool `json:"sentinel"` Secure bool `json:"secure"` }
ConfigRedis is an optional Redis configuration parameters.
type ConnectionEstablishedData ¶
type ConnectionEstablishedData struct { SocketID string `json:"socket_id"` ActivityTimeout int `json:"activity_timeout"` }
ConnectionEstablishedData is a struct to return pusher:connection_established event to the client.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB encapsulates Redis operation from other parts
func (*DB) AddUserIDToChannel ¶
AddUserIDToChannel adds UID to the list of subscribers in the specified channel.
func (*DB) DeleteUserID ¶
DeleteUserID deletes the given user id. Note: The user must have been unsubscribed from all the channels. Supervisor.RemoveUser takes care of that.
func (*DB) DeleteUserIDFromChannel ¶
DeleteUserIDFromChannel removes the given uid from the subscribers of the specified channel.
func (*DB) GetAllUserIDs ¶
GetAllUserIDs returns all user IDs in the given app.
func (*DB) GetChannel ¶
GetChannel returns the named channel. The named channel must exist.
func (*DB) GetChannels ¶
GetChannels returns map of channel names to channels
type EventRequest ¶
type EventRequest struct { Name string // event name Data string // event payload Application string // application name Channel string // target channel name }
EventRequest is a packet dispersed via pubsub channel
type PusherEvent ¶
type PusherEvent struct { Event string `json:"event"` Data string `json:"data"` Channel string `json:"channel",omitempty` }
PusherEvent is a struct to receive Pusher message. See https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#events
type Supervisor ¶
type Supervisor struct { Port int Apps []*Application Config *Config // contains filtered or unexported fields }
Supervisor is the root of runtime data structure.
func NewSupervisor ¶
func NewSupervisor(config *Config) *Supervisor
NewSupervisor creates a new Supervisor.
func (*Supervisor) AddUser ¶
AddUser creates a new user associated to an application, with the given connection.
func (*Supervisor) Broadcast ¶
func (s *Supervisor) Broadcast(a *Application, e *Event, cn string) error
Broadcast sends out the event to the users who subscribe the given channel. In distributed mode, we don't know which process is managing the user, so we use Redis Keyspace Notification.
func (*Supervisor) GetApp ¶
func (s *Supervisor) GetApp(name string) (*Application, error)
GetApp returns the named application.
func (*Supervisor) GetAppFromKey ¶
func (s *Supervisor) GetAppFromKey(key string) (*Application, error)
GetAppFromKey returns the application with specified key.
func (*Supervisor) GetChannel ¶
func (s *Supervisor) GetChannel(appname string, channame string) (*Channel, error)
GetChannel returns the named channel in the named application. If there's no such channel, 404 error is returned.
func (*Supervisor) GetChannels ¶
func (s *Supervisor) GetChannels(appname string) (map[string]*Channel, error)
GetChannels returns an array of channels in the given app
func (*Supervisor) GetOrCreateChannel ¶
func (s *Supervisor) GetOrCreateChannel(appname string, channame string) (*Channel, error)
GetOrCreateChannel returns the named channel in the named application. If there's no such channel, create it.
func (*Supervisor) KickRedisSubscription ¶
func (s *Supervisor) KickRedisSubscription()
KickRedisSubscription starts goroutine to handle Redis events.
func (*Supervisor) PublishRedisEvent ¶
func (s *Supervisor) PublishRedisEvent(ev *EventRequest) error
PublishRedisEvent pushes Redis events.
func (*Supervisor) RemoveUser ¶
func (s *Supervisor) RemoveUser(appname string, uid int) error
RemoveUser removes the specified user from the application and associated channels. NB: The user's connection must be cleaned up by the caller (see socket.go)
func (*Supervisor) Subscribe ¶
func (s *Supervisor) Subscribe(appname string, uid int, channame string) error
Subscribe let the user subscribe the named channel The user with UID must be managed by this process (when socket.go calls this, it should.)
func (*Supervisor) Unsubscribe ¶
func (s *Supervisor) Unsubscribe(appname string, uid int, channame string) error
Unsubscribe let the user unsubscribe the named channel The user with UID must be managed by this process (when socket.go calls this, it should.)