Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 28, 2022 08:33
Show Gist options
  • Save percybolmer/30f50e7d55d4eb1be4abefc9d8c9dcd9 to your computer and use it in GitHub Desktop.
Save percybolmer/30f50e7d55d4eb1be4abefc9d8c9dcd9 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
"github.com/gorilla/websocket"
)
var (
/**
websocketUpgrader is used to upgrade incomming HTTP requests into a persitent websocket connection
*/
websocketUpgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
)
// Manager is used to hold references to all Clients Registered, and Broadcasting etc
type Manager struct {
}
// NewManager is used to initalize all the values inside the manager
func NewManager() *Manager {
return &Manager{}
}
// 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
}
// We wont do anything yet so close connection again
conn.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment