func NewServerWebSocket(server *http.Server, upgrader *websocket.Upgrader) Server {
	// TODO: wait, what if they already have a server and want to control serve, close, and handler?
	if upgrader == nil {
		upgrader = &websocket.Upgrader{}
	}
	s := &serverWebSocket{
		server:     server,
		acceptCh:   make(chan *websocket.Conn),
		serveErrCh: make(chan error, 1),
	}
	// Setup the accepter
	s.acceptCtx, s.acceptCancelFn = context.WithCancel(context.Background())
	server.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		conn, err := upgrader.Upgrade(w, r, nil)
		if err != nil {
			if server.ErrorLog != nil {
				server.ErrorLog.Printf("Failed upgrading websocket: %v", err)
			}
			return
		}
		select {
		case <-s.acceptCtx.Done():
		case s.acceptCh <- conn:
		}
	})
	return s
}
// NewServerWebSocket creates a new Server for the given HTTP server and given upgrader.
NewServerWebSocket creates a new Server for the given HTTP server and given upgrader.
// NewServerWebSocket creates a new Server for the given HTTP server and given upgrader .
func NewServerWebSocket(server *http.Server, upgrader *websocket.Upgrader) Server {
	if upgrader == nil {
		upgrader = &websocket.Upgrader{}
	}
	s := &serverWebSocket{
		server:     server,
		acceptCh:   make(chan *websocket.Conn),
		serveErrCh: make(chan error, 1),
	}
	s.acceptCtx, s.acceptCancelFn = context.WithCancel(context.Background())
	server.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		conn, err := upgrader.Upgrade(w, r, nil)
		if err != nil {
			if server.ErrorLog != nil {
				server.ErrorLog.Printf("Failed upgrading websocket: %v", err)
			}
			return
		}
		select {
		case <-s.acceptCtx.Done():
		case s.acceptCh <- conn:
		}
	})
	return s
}
func NewServerWebSocket ( server * http . Server , upgrader * websocket . Upgrader ) Server { if upgrader == nil { upgrader = & websocket . Upgrader { } } s := & serverWebSocket { server : server , acceptCh : make ( chan * websocket . Conn ) , serveErrCh : make ( chan error , 1 ) , } s . acceptCtx , s . acceptCancelFn = context . WithCancel ( context . Background ( ) ) server . Handler = http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { conn , err := upgrader . Upgrade ( w , r , nil ) if err != nil { if server . ErrorLog != nil { server . ErrorLog . Printf ( " " , err ) } return } select { case <- s . acceptCtx . Done ( ) : case s . acceptCh <- conn : } } ) return s }
NewServerWebSocket creates a new Server for the given HTTP server and given upgrader.
NewServerWebSocket creates a new Server for the given HTTP server and given upgrader .
// TODO: wait, what if they already have a server and want to control serve, close, and handler? // Setup the accepter