mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-22 14:20:29 +01:00
select players position from database.
This commit is contained in:
parent
8c6ab34e6a
commit
1ec9d8916b
@ -22,7 +22,10 @@ import (
|
|||||||
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sleepInterval = time.Second * 5
|
const (
|
||||||
|
sleepInterval = time.Second * 5
|
||||||
|
sleepPG = time.Second
|
||||||
|
)
|
||||||
|
|
||||||
var geoJSONTmpl = template.Must(template.New("geojson").Parse(
|
var geoJSONTmpl = template.Must(template.New("geojson").Parse(
|
||||||
`{ "type": "Feature",
|
`{ "type": "Feature",
|
||||||
@ -83,11 +86,12 @@ func (pls sortPlayersByName) Swap(i, j int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selectPlayersSQL = `
|
const selectPlayersSQL = `
|
||||||
SELECT posx, posy, posz, name
|
SELECT posx/10.0, posy/10.0, posz/10.0, name
|
||||||
FROM player
|
FROM player
|
||||||
WHERE modification_date > now() - '2m'::interval`
|
WHERE modification_date > now() - '2m'::interval`
|
||||||
|
|
||||||
func playersFromPostgreSQL(connS string) ([]*player, error) {
|
func playersFromPostgreSQL(connS string) ([]*player, error) {
|
||||||
|
time.Sleep(sleepPG)
|
||||||
db, err := sql.Open("pgx", connS)
|
db, err := sql.Open("pgx", connS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -101,7 +105,7 @@ func playersFromPostgreSQL(connS string) ([]*player, error) {
|
|||||||
var pls []*player
|
var pls []*player
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var p player
|
var p player
|
||||||
if err := rows.Scan(&p.Y, &p.Y, &p.Z, &p.Name); err != nil {
|
if err := rows.Scan(&p.X, &p.Y, &p.Z, &p.Name); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pls = append(pls, &p)
|
pls = append(pls, &p)
|
||||||
|
Loading…
Reference in New Issue
Block a user