Add HTTP layer and server setup

- Add strict configuration management (no fallbacks)
- Create HTTP router with Chi and CORS middleware
- Implement health check endpoint
- Add main entry point with database initialization
- Server runs on configurable host and port
This commit is contained in:
2025-11-26 00:21:07 +01:00
parent 34ea1f718e
commit 76893bd114
5 changed files with 146 additions and 1 deletions
+33
View File
@@ -0,0 +1,33 @@
package main
import (
"fmt"
"log"
"net/http"
"habit-tracker-api/internal/infrastructure/config"
httpInfra "habit-tracker-api/internal/infrastructure/http"
"habit-tracker-api/internal/infrastructure/persistence/sqlite"
)
func main() {
cfg, err := config.Load()
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
db, err := sqlite.NewDatabase(cfg.DBPath)
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
defer db.Close()
router := httpInfra.NewRouter(cfg.CORSOrigins)
addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
log.Printf("Server starting on %s", addr)
if err := http.ListenAndServe(addr, router); err != nil {
log.Fatalf("Server failed: %v", err)
}
}