Wire websocket forwarder with players updater.

This commit is contained in:
Sascha L. Teichmann 2015-03-09 13:16:31 +01:00
parent ece8924355
commit da51389935
2 changed files with 11 additions and 9 deletions

View File

@ -65,20 +65,21 @@ func main() {
router.Path("/map/{z:[0-9]+}/{x:[0-9]+}/{y:[0-9]+}.png").Handler(subBaseLine) router.Path("/map/{z:[0-9]+}/{x:[0-9]+}/{y:[0-9]+}.png").Handler(subBaseLine)
var btu baseTilesUpdates var btu baseTilesUpdates
var wsf *websocketForwarder
if playersFIFO != "" {
plys := newPlayers(playersFIFO)
go plys.run()
router.Path("/players").Methods("GET").Handler(plys)
}
if websockets { if websockets {
wsf := newWebsocketForwarder() wsf = newWebsocketForwarder()
go wsf.run() go wsf.run()
router.Path("/ws").Methods("GET").Handler(wsf) router.Path("/ws").Methods("GET").Handler(wsf)
btu = wsf btu = wsf
} }
if playersFIFO != "" {
plys := newPlayers(playersFIFO, wsf)
go plys.run()
router.Path("/players").Methods("GET").Handler(plys)
}
if redisHost != "" { if redisHost != "" {
var colors *common.Colors var colors *common.Colors
var err error var err error

View File

@ -4,10 +4,11 @@ import "net/http"
type players struct { type players struct {
fifo string fifo string
wsf *websocketForwarder
} }
func newPlayers(fifo string) *players { func newPlayers(fifo string, wsf *websocketForwarder) *players {
return &players{fifo: fifo} return &players{fifo: fifo, wsf: wsf}
} }
func (ps *players) run() { func (ps *players) run() {