Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger interface { Infof(format string, v ...interface{}) Errorf(format string, v ...interface{}) }
Logger defines the shape of the component needed by the gowse server and topics to log info and errors.
type Server ¶
Server allows to create topics that clients can subscribe to.
func NewServer ¶
NewServer creates and initializes a gowse Server. If the logger argument is nil the logs written by the server will be discarded.
func (*Server) CreateTopic ¶
CreateTopic creates a topic where clients can connect to receive messages.
func (*Server) Stop ¶
func (s *Server) Stop()
Stop signals all the topics created by the server to finish and blocks the calling goroutine until all the Topics have finished. The caller must ensure all the calls to topic.TopicHandler had completed and no futher calls to that method will be made. That usually means the http server receiving the client subscritions has already been stopped.
type Subscriber ¶
type Subscriber struct { ID string // contains filtered or unexported fields }
Subscriber represents a client subscribed to a topic.
func NewSubscriber ¶
func NewSubscriber(w http.ResponseWriter, r *http.Request, t *Topic) (*Subscriber, error)
NewSubscriber creates a subscriber by upgrading the http request to a websocket.
func (*Subscriber) Close ¶
func (s *Subscriber) Close()
Close closes the underlaying connection with the subscriber.
func (*Subscriber) Monitor ¶
func (s *Subscriber) Monitor(closed chan<- *Subscriber)
Monitor detects when a subscriber closed a connection.
func (*Subscriber) SendMessage ¶
func (s *Subscriber) SendMessage(msg interface{}) error
SendMessage sends a message to the subscriber.
type Topic ¶
type Topic struct { ID string // contains filtered or unexported fields }
Topic represents and endpoint where multiple clients can subscribe to receive the broadcasted messages.
func (*Topic) Broadcast ¶
func (t *Topic) Broadcast(message interface{})
Broadcast sends a messages to the all the clients subscribed to the topic. Calling broadcast after canceling the context passed to the server that created the topic causes panic.
func (*Topic) Process ¶
Process starts the topic to accept new subscribers and to broadcast messages.
func (*Topic) SubscriberHandler ¶
SubscriberHandler is called when a new subscriber connects to the topic.