mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
31 lines
526 B
Go
31 lines
526 B
Go
package web
|
|
|
|
import (
|
|
"code.google.com/p/go.net/websocket"
|
|
)
|
|
|
|
type connection struct {
|
|
// The websocket connection.
|
|
ws *websocket.Conn
|
|
|
|
// Buffered channel of outbound messages.
|
|
send chan string
|
|
}
|
|
|
|
func (c *connection) writer() {
|
|
for message := range c.send {
|
|
err := websocket.Message.Send(c.ws, message)
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
c.ws.Close()
|
|
}
|
|
|
|
func wsHandler(ws *websocket.Conn) {
|
|
c := &connection{send: make(chan string, 256), ws: ws}
|
|
h.register <- c
|
|
defer func() { h.unregister <- c }()
|
|
c.writer()
|
|
}
|