diff --git a/cmd/mtwebmapper/players.go b/cmd/mtwebmapper/players.go index 227049e..947f5e5 100644 --- a/cmd/mtwebmapper/players.go +++ b/cmd/mtwebmapper/players.go @@ -2,8 +2,11 @@ package main import ( "bytes" + "encoding/json" "html/template" + "log" "net/http" + "sync" ) var geoJSONTmpl = template.Must(template.New("geojson").Parse( @@ -28,6 +31,7 @@ type players struct { fifo string wsf *websocketForwarder pls []*player + mu sync.RWMutex } func newPlayers(fifo string, wsf *websocketForwarder) *players { @@ -49,5 +53,11 @@ func (ps *players) run() { } func (ps *players) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - // TODO: Implement me! + rw.Header().Set("Content-Type", "application/json") + ps.mu.RLock() + defer ps.mu.RUnlock() + encoder := json.NewEncoder(rw) + if err := encoder.Encode(ps.pls); err != nil { + log.Printf("error: sending JSON failed: %s\n", err) + } }