/
sensor.go
executable file
·66 lines (57 loc) · 2.8 KB
/
sensor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package handlers
import (
"net/http"
entities "github.com/gost/core"
"github.com/gost/server/sensorthings/models"
"github.com/gost/server/sensorthings/odata"
"github.com/gost/server/sensorthings/rest/reader"
)
// HandleGetSensorByDatastream ...
func HandleGetSensorByDatastream(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
handle := func(q *odata.QueryOptions, path string) (interface{}, error) {
return a.GetSensorByDatastream(reader.GetEntityID(r), q, path)
}
handleGetRequest(w, endpoint, r, &handle, a.GetConfig().Server.IndentedJSON, a.GetConfig().Server.MaxEntityResponse, a.GetConfig().Server.ExternalURI)
}
// HandleGetSensor ...
func HandleGetSensor(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
handle := func(q *odata.QueryOptions, path string) (interface{}, error) {
return a.GetSensor(reader.GetEntityID(r), q, path)
}
handleGetRequest(w, endpoint, r, &handle, a.GetConfig().Server.IndentedJSON, a.GetConfig().Server.MaxEntityResponse, a.GetConfig().Server.ExternalURI)
}
// HandleGetSensors ...
func HandleGetSensors(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
handle := func(q *odata.QueryOptions, path string) (interface{}, error) { return a.GetSensors(q, path) }
handleGetRequest(w, endpoint, r, &handle, a.GetConfig().Server.IndentedJSON, a.GetConfig().Server.MaxEntityResponse, a.GetConfig().Server.ExternalURI)
}
// HandlePostSensors ...
func HandlePostSensors(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
sensor := &entities.Sensor{}
handle := func() (interface{}, []error) { return a.PostSensor(sensor) }
handlePostRequest(w, endpoint, r, sensor, &handle, a.GetConfig().Server.IndentedJSON)
}
// HandleDeleteSensor ...
func HandleDeleteSensor(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
handle := func() error { return a.DeleteSensor(reader.GetEntityID(r)) }
handleDeleteRequest(w, endpoint, r, &handle, a.GetConfig().Server.IndentedJSON)
}
// HandlePatchSensor ...
func HandlePatchSensor(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
sensor := &entities.Sensor{}
handle := func() (interface{}, error) { return a.PatchSensor(reader.GetEntityID(r), sensor) }
handlePatchRequest(w, endpoint, r, sensor, &handle, a.GetConfig().Server.IndentedJSON)
}
// HandlePutSensor ...
func HandlePutSensor(w http.ResponseWriter, r *http.Request, endpoint *models.Endpoint, api *models.API) {
a := *api
sensor := &entities.Sensor{}
handle := func() (interface{}, []error) { return a.PutSensor(reader.GetEntityID(r), sensor) }
handlePutRequest(w, endpoint, r, sensor, &handle, a.GetConfig().Server.IndentedJSON)
}