1
0
forked from MTSR/mapserver
mapserver/web/mapobjects.go

41 lines
771 B
Go
Raw Normal View History

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