Routes package
This commit is contained in:
parent
f6de3fdfbf
commit
9d5c19f671
11
main.go
11
main.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"basic-sensor-receiver/app"
|
||||
"basic-sensor-receiver/routes"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -23,11 +24,11 @@ func main() {
|
|||
protected.Static("/js", "client/js")
|
||||
protected.Static("/css", "client/css")
|
||||
|
||||
protected.GET("/api/sensors", server.GetSensors())
|
||||
protected.GET("/api/sensors/:sensor/values", server.HandleGetSensorValues())
|
||||
protected.POST("/api/sensors/:sensor/values", server.HandlePostSensorValues())
|
||||
protected.GET("/api/sensors/:sensor/config", server.GetSensorConfig())
|
||||
protected.PUT("/api/sensors/:sensor/config/:key", server.HandlePutSensorConfig())
|
||||
protected.GET("/api/sensors", routes.GetSensors(server))
|
||||
protected.GET("/api/sensors/:sensor/values", routes.HandleGetSensorValues(server))
|
||||
protected.POST("/api/sensors/:sensor/values", routes.HandlePostSensorValues(server))
|
||||
protected.GET("/api/sensors/:sensor/config", routes.GetSensorConfig(server))
|
||||
protected.PUT("/api/sensors/:sensor/config/:key", routes.HandlePutSensorConfig(server))
|
||||
|
||||
router.Run(fmt.Sprintf("%s:%d", server.Config.Ip, server.Config.Port))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package app
|
||||
package routes
|
||||
|
||||
import (
|
||||
"basic-sensor-receiver/app"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -10,7 +11,7 @@ type sensorConfigValue struct {
|
|||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
func (s *Server) HandlePutSensorConfig() gin.HandlerFunc {
|
||||
func HandlePutSensorConfig(s *app.Server) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var configValue sensorConfigValue
|
||||
sensor := c.Param("sensor")
|
||||
|
|
@ -30,7 +31,7 @@ func (s *Server) HandlePutSensorConfig() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) GetSensorConfig() gin.HandlerFunc {
|
||||
func GetSensorConfig(s *app.Server) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
sensor := c.Param("sensor")
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package app
|
||||
package routes
|
||||
|
||||
import (
|
||||
"basic-sensor-receiver/app"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -15,7 +16,7 @@ type getSensorQuery struct {
|
|||
To int64 `form:"to"`
|
||||
}
|
||||
|
||||
func (s *Server) HandlePostSensorValues() gin.HandlerFunc {
|
||||
func HandlePostSensorValues(s *app.Server) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var newValue postSensorValueBody
|
||||
sensor := c.Param("sensor")
|
||||
|
|
@ -34,7 +35,7 @@ func (s *Server) HandlePostSensorValues() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) HandleGetSensorValues() gin.HandlerFunc {
|
||||
func HandleGetSensorValues(s *app.Server) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var query getSensorQuery
|
||||
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package app
|
||||
package routes
|
||||
|
||||
import (
|
||||
"basic-sensor-receiver/app"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (s *Server) GetSensors() gin.HandlerFunc {
|
||||
func GetSensors(s *app.Server) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
sensors, err := s.Services.Sensors.GetList()
|
||||
|
||||
Loading…
Reference in New Issue