server

package
v0.0.0-...-346be84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

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 NewServer

func NewServer(sub int, port string) *Server

func (*Server) AddSubscriber

func (s *Server) AddSubscriber(subscriber *Subscriber)

func (*Server) Broadcast

func (s *Server) Broadcast(msg []byte)

broadcast all the messages to all connected subscribers via channels note the usage of Mutex to protect the thread

func (*Server) GetHardwareData

func (s *Server) GetHardwareData() (string, string, string)

func (*Server) Subscribe

func (s *Server) Subscribe(ctx context.Context, w http.ResponseWriter, r *http.Request) error

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL