mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Added JSON marshaller for players.
This commit is contained in:
parent
da51389935
commit
cbfb594c83
@ -1,16 +1,47 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var geoJSONTmpl = template.Must(template.New("geojson").Parse(
|
||||||
|
`{ "type": "Feature",
|
||||||
|
"geometry": {
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [{{.X}}, {{.Z}}]
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"name": {{.Name || html }}
|
||||||
|
}
|
||||||
|
}`))
|
||||||
|
|
||||||
|
type player struct {
|
||||||
|
X float64
|
||||||
|
Y float64
|
||||||
|
Z float64
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
type players struct {
|
type players struct {
|
||||||
fifo string
|
fifo string
|
||||||
wsf *websocketForwarder
|
wsf *websocketForwarder
|
||||||
|
pls []*player
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPlayers(fifo string, wsf *websocketForwarder) *players {
|
func newPlayers(fifo string, wsf *websocketForwarder) *players {
|
||||||
return &players{fifo: fifo, wsf: wsf}
|
return &players{fifo: fifo, wsf: wsf}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *player) MarshalJSON() ([]byte, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := geoJSONTmpl.Execute(&buf, p); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ps *players) run() {
|
func (ps *players) run() {
|
||||||
for {
|
for {
|
||||||
// TODO: Implement me!
|
// TODO: Implement me!
|
||||||
|
Loading…
Reference in New Issue
Block a user