Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created September 7, 2022 13:15
Show Gist options
  • Save percybolmer/e5af31aa5e988bebc5207e94f48fff5f to your computer and use it in GitHub Desktop.
Save percybolmer/e5af31aa5e988bebc5207e94f48fff5f to your computer and use it in GitHub Desktop.
// serveWS is a HTTP Handler that the has the Manager that allows connections
func (m *Manager) serveWS(w http.ResponseWriter, r *http.Request) {
log.Println("New connection")
// Begin by upgrading the HTTP request
conn, err := websocketUpgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
return
}
// Create New Client
client := NewClient(conn, m)
// Add the newly created client to the manager
m.addClient(client)
// Start the read / write processes
go client.readMessages()
// go client.writeMessages()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment