kopia lustrzana https://github.com/cyoung/stratux
Add SendJSON() to uibroadcaster.
rodzic
27206c0751
commit
504d97ec7a
|
@ -11,6 +11,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"golang.org/x/net/websocket"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -36,6 +37,11 @@ func (u *uibroadcaster) Send(msg []byte) {
|
|||
u.messages <- msg
|
||||
}
|
||||
|
||||
func (u *uibroadcaster) SendJSON(i interface{}) {
|
||||
j, _ := json.Marshal(&i)
|
||||
u.Send(j)
|
||||
}
|
||||
|
||||
func (u *uibroadcaster) AddSocket(sock *websocket.Conn) {
|
||||
u.sockets_mu.Lock()
|
||||
u.sockets = append(u.sockets, sock)
|
||||
|
|
Ładowanie…
Reference in New Issue