42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"basic-sensor-receiver/app"
|
|
"basic-sensor-receiver/routes"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/joho/godotenv"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func main() {
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
log.Println("Error loading .env file")
|
|
}
|
|
|
|
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", 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))
|
|
}
|