34 lines
924 B
Go
34 lines
924 B
Go
package main
|
|
|
|
import (
|
|
"basic-sensor-receiver/app"
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func main() {
|
|
server := app.InitializeServer()
|
|
|
|
gin.SetMode(server.Config.Mode)
|
|
|
|
router := gin.Default()
|
|
|
|
protected := router.Group("/", gin.BasicAuth(gin.Accounts{
|
|
server.Config.AuthUsername: server.Config.AuthPassword,
|
|
}))
|
|
|
|
protected.StaticFile("/", "client/index.html")
|
|
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())
|
|
|
|
router.Run(fmt.Sprintf("%s:%d", server.Config.Ip, server.Config.Port))
|
|
}
|