mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Serve GeoJSON encoded players via /players.
This commit is contained in:
parent
cbfb594c83
commit
ff08f2af94
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user