You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
|
|
"git.aiterp.net/lucifer/lucifer/light"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"git.aiterp.net/lucifer/lucifer/controllers"
|
|
"git.aiterp.net/lucifer/lucifer/database/sqlite"
|
|
"git.aiterp.net/lucifer/lucifer/internal/config"
|
|
"git.aiterp.net/lucifer/lucifer/middlewares"
|
|
|
|
_ "git.aiterp.net/lucifer/lucifer/light/hue"
|
|
)
|
|
|
|
func main() {
|
|
// Setup
|
|
conf, err := config.Load("./config.yaml", "/etc/lucifer/lucifer.yaml")
|
|
if err != nil {
|
|
log.Fatalln("Failed to load configuration:", err)
|
|
}
|
|
|
|
err = sqlite.Initialize(conf.DB.FileName)
|
|
if err != nil {
|
|
log.Fatalln("Failed to set up database:", err)
|
|
}
|
|
|
|
// Services
|
|
lightService := light.NewService(sqlite.BridgeRepository, sqlite.LightRepository)
|
|
|
|
// Controllers
|
|
userController := controllers.NewUserController(sqlite.UserRepository, sqlite.SessionRepository)
|
|
|
|
// Router
|
|
router := mux.NewRouter()
|
|
router.Use(middlewares.Session(sqlite.SessionRepository))
|
|
userController.Mount(router, "/api/user/")
|
|
|
|
// Background Tasks
|
|
go lightService.SyncLoop(context.TODO())
|
|
|
|
// TODO: Listen in another goroutine and have SIGINT/SIGTERM handlers with graceful shutdown.
|
|
http.ListenAndServe(conf.Server.Address, router)
|
|
}
|