/
sensors.go
41 lines (33 loc) · 921 Bytes
/
sensors.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
package api
import (
"errors"
"github.com/labstack/echo/v4"
"github.com/markusressel/fan2go/internal/sensors"
"net/http"
)
func registerSensorEndpoints(rest *echo.Echo) {
group := rest.Group("/sensor")
group.GET("/", getSensors)
group.GET("/:"+urlParamId+"/", getSensor)
group.POST("/", createSensor)
group.DELETE("/:"+urlParamId+"/", deleteSensor)
}
func getSensors(c echo.Context) error {
data := sensors.SensorMap
return c.JSONPretty(http.StatusOK, data, indentationChar)
}
func getSensor(c echo.Context) error {
id := c.Param(urlParamId)
data, exists := sensors.SensorMap[id]
if !exists {
return returnNotFound(c, id)
} else {
return c.JSONPretty(http.StatusOK, data, indentationChar)
}
}
func createSensor(c echo.Context) error {
return returnError(c, errors.New("not yet supported"))
}
func deleteSensor(c echo.Context) error {
return returnError(c, errors.New("not yet supported"))
}