Documentation
¶
Index ¶
- type Server
- func (s *Server) AddSubscriber(subscriber *Subscriber)
- func (s *Server) Broadcast(msg []byte)
- func (s *Server) GetHardwareData() (string, string, string)
- func (s *Server) Subscribe(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- func (s *Server) SubscribeHandler(w http.ResponseWriter, r *http.Request)
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
Port string
// to keep track of Subscribers
// we create a map of subscribers
// as anonymous struct
Subscribers map[*Subscriber]struct{} // anonymous struct
Mux http.ServeMux
SubscriberMutex sync.Mutex
SubscriberMessageBuffer int
}
func (*Server) AddSubscriber ¶
func (s *Server) AddSubscriber(subscriber *Subscriber)
func (*Server) Broadcast ¶
broadcast all the messages to all connected subscribers via channels note the usage of Mutex to protect the thread
func (*Server) Subscribe ¶
Subscribe by creating connections that we can keep track and able to send messages to that connection
func (*Server) SubscribeHandler ¶
func (s *Server) SubscribeHandler(w http.ResponseWriter, r *http.Request)
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.