2019-01-28 10:42:07 +01:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
2019-01-28 11:45:23 +01:00
|
|
|
"encoding/json"
|
2019-01-28 10:42:07 +01:00
|
|
|
"mapserver/app"
|
|
|
|
"mapserver/mapobjectdb"
|
|
|
|
"net/http"
|
2019-02-22 18:30:38 +01:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2019-01-28 10:42:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type MapObjects struct {
|
|
|
|
ctx *app.App
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MapObjects) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
|
|
|
|
2019-02-15 08:36:48 +01:00
|
|
|
timer := prometheus.NewTimer(mapobjectServeDuration)
|
|
|
|
defer timer.ObserveDuration()
|
|
|
|
|
2019-02-22 14:57:40 +01:00
|
|
|
decoder := json.NewDecoder(req.Body)
|
2019-02-22 18:30:38 +01:00
|
|
|
q := mapobjectdb.SearchQuery{}
|
2019-01-28 10:42:07 +01:00
|
|
|
|
2019-02-22 14:57:40 +01:00
|
|
|
err := decoder.Decode(&q)
|
2019-01-28 10:42:07 +01:00
|
|
|
if err != nil {
|
|
|
|
resp.WriteHeader(500)
|
|
|
|
resp.Write([]byte(err.Error()))
|
2019-02-22 14:57:40 +01:00
|
|
|
return
|
|
|
|
}
|
2019-01-28 10:42:07 +01:00
|
|
|
|
2019-02-22 18:30:38 +01:00
|
|
|
objects, err := t.ctx.Objectdb.GetMapData(&q)
|
2019-02-22 14:57:40 +01:00
|
|
|
if err != nil {
|
|
|
|
resp.WriteHeader(500)
|
|
|
|
resp.Write([]byte(err.Error()))
|
|
|
|
return
|
2019-01-28 10:42:07 +01:00
|
|
|
}
|
2019-02-22 14:57:40 +01:00
|
|
|
|
|
|
|
resp.Header().Add("content-type", "application/json")
|
|
|
|
json.NewEncoder(resp).Encode(objects)
|
2019-01-28 10:42:07 +01:00
|
|
|
}
|