mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 09:10:17 +01:00
Serve GeoJSON encoded players via /players.
This commit is contained in:
parent
cbfb594c83
commit
ff08f2af94
@ -2,8 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var geoJSONTmpl = template.Must(template.New("geojson").Parse(
|
var geoJSONTmpl = template.Must(template.New("geojson").Parse(
|
||||||
@ -28,6 +31,7 @@ type players struct {
|
|||||||
fifo string
|
fifo string
|
||||||
wsf *websocketForwarder
|
wsf *websocketForwarder
|
||||||
pls []*player
|
pls []*player
|
||||||
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPlayers(fifo string, wsf *websocketForwarder) *players {
|
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) {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user