Merge feature/phase2-sqlite-sync into main

This commit is contained in:
2026-02-03 22:04:17 +03:00
9 changed files with 170 additions and 67 deletions

View File

@@ -15,7 +15,7 @@ import (
"syscall"
"time"
"github.com/gin-gonic/gin"
qfassets "git.mchus.pro/mchus/quoteforge"
"git.mchus.pro/mchus/quoteforge/internal/config"
"git.mchus.pro/mchus/quoteforge/internal/db"
"git.mchus.pro/mchus/quoteforge/internal/handlers"
@@ -28,6 +28,7 @@ import (
"git.mchus.pro/mchus/quoteforge/internal/services/pricelist"
"git.mchus.pro/mchus/quoteforge/internal/services/pricing"
"git.mchus.pro/mchus/quoteforge/internal/services/sync"
"github.com/gin-gonic/gin"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
@@ -69,9 +70,14 @@ func main() {
// Load config for server settings (optional)
cfg, err := config.Load(*configPath)
if err != nil {
// Use defaults if config file doesn't exist
slog.Info("config file not found, using defaults", "path", *configPath)
cfg = &config.Config{}
if os.IsNotExist(err) {
// Use defaults if config file doesn't exist
slog.Info("config file not found, using defaults", "path", *configPath)
cfg = &config.Config{}
} else {
slog.Error("failed to load config", "path", *configPath, "error", err)
os.Exit(1)
}
}
setConfigDefaults(cfg)
@@ -238,7 +244,11 @@ func runSetupMode(local *localdb.LocalDB) {
router.Use(gin.Recovery())
staticPath := filepath.Join("web", "static")
router.Static("/static", staticPath)
if stat, err := os.Stat(staticPath); err == nil && stat.IsDir() {
router.Static("/static", staticPath)
} else if staticFS, err := qfassets.StaticFS(); err == nil {
router.StaticFS("/static", http.FS(staticFS))
}
// Setup routes only
router.GET("/", func(c *gin.Context) {
@@ -445,7 +455,11 @@ func setupRouter(cfg *config.Config, local *localdb.LocalDB, connMgr *db.Connect
// Static files (use filepath.Join for Windows compatibility)
staticPath := filepath.Join("web", "static")
router.Static("/static", staticPath)
if stat, err := os.Stat(staticPath); err == nil && stat.IsDir() {
router.Static("/static", staticPath)
} else if staticFS, err := qfassets.StaticFS(); err == nil {
router.StaticFS("/static", http.FS(staticFS))
}
// Health check
router.GET("/health", func(c *gin.Context) {