func incoming(msgs chan *message.Message) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { if incoming, err := ioutil.ReadAll(r.Body); err == nil { if m, open_error := message.Open(incoming); open_error == nil { /* Send in the message! */ msgs <- m } else { log.Error(open_error.Error()) } } } }
func (c *connection) listen() { log.Info("New connection ...") for { /* Keep reading in messages for as long as necessary */ _, msg, err := c.WS.ReadMessage() if err != nil { /* Here? Connection dropped ... unregister the connection */ delete(connections, c) log.Info(c.Signature + " left") break } else { if m, err := message.Open(msg); err == nil { c.Signature = m.Signature c.Msgs <- m } else { log.Error("Unable to open message") } } } }