server

package
v0.0.0-...-40d9c4a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageDecodeError = `message decoding failed`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Recepient string `json:"recepient"`
	Body      string `json:"body"`
}

type Server

type Server struct {
	sync.Mutex
	Connections map[string]*User
	Upgrader    websocket.Upgrader
}

Server is our websocket server.

func New

func New() *Server

New creates a new websocket server.

func (*Server) Listener

func (s *Server) Listener(u *User)

Listener method listens to new messages from the user who has established a ws connection with server.

func (*Server) SendToAll

func (s *Server) SendToAll(sender string, msg *Message)

SendToAll method broadcasts a message to all users connected to the server.

func (*Server) WebsocketHandler

func (s *Server) WebsocketHandler(w http.ResponseWriter, r *http.Request)

WebsocketHandler handles a websocket conn initiation and starts a listener.

type User

type User struct {
	Username string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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