Files
hireme/cmd/hireme/main.go
T

90 lines
2.7 KiB
Go

package main
import (
"fmt"
"net/http"
"os"
"path/filepath"
"github.com/hireme/hireme/internal/analyzer"
"github.com/hireme/hireme/internal/config"
"github.com/hireme/hireme/internal/db"
"github.com/hireme/hireme/internal/logger"
"github.com/hireme/hireme/internal/ui"
"github.com/hireme/hireme/internal/worker"
"github.com/spf13/cobra"
)
var cfg *config.Config
func newRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "hireme",
Short: "Hireme (GJCC) - High Performance Job Application Command Center",
Long: `Hireme is a high-performance single-binary job application and tracking command center written in Go.`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg.Normalize()
logger.SetLevel(cfg.LogLevel)
logger.Log.Info("==========================================================")
logger.Log.Info("🚀 Starting Hireme (GJCC) Job Application Command Center")
logger.Log.Info("==========================================================")
logger.Log.Infow("Starting Hireme", "component", "Config", "port", cfg.Port, "db_path", cfg.DBPath, "target_config", cfg.TargetConfig, "llm", cfg.LLMProvider, "log_level", cfg.LogLevel)
// Ensure DB directory exists
dbDir := filepath.Dir(cfg.DBPath)
if dbDir != "." && dbDir != "" {
_ = os.MkdirAll(dbDir, 0755)
}
// Initialize Database
database, err := db.InitDB(cfg.DBPath)
if err != nil {
return fmt.Errorf("fatal DB error: %w", err)
}
defer func() { _ = database.Close() }()
// Load targets from YAML config if database is empty
if err := database.LoadTargetsFromYAML(cfg.TargetConfig); err != nil {
logger.Log.Errorw("Target YAML loading failed", "component", "Main", "error", err)
}
// Initialize LLM Analyzer
llmAnalyzer, err := analyzer.NewAnalyzer(cfg)
if err != nil {
return fmt.Errorf("fatal Analyzer setup error: %w", err)
}
// Load filter configuration
filterCfg, err := config.LoadFilterConfig(cfg.FilterConfig)
if err != nil {
logger.Log.Fatalw("Failed to load filter config", "component", "Main", "error", err)
}
// 4. Initialize Worker Pool
pool := worker.NewWorkerPool(database, llmAnalyzer, 3, filterCfg)
pool.Start() // Auto start the worker pool
// Setup UI Server & Routes
server := ui.NewServer(cfg, database, pool)
mux := http.NewServeMux()
server.RegisterRoutes(mux)
addr := fmt.Sprintf(":%s", cfg.Port)
logger.Log.Infow("Hireme Command Center is live", "component", "Main", "url", fmt.Sprintf("http://localhost:%s", cfg.Port))
return http.ListenAndServe(addr, mux)
},
}
cfg = config.RegisterFlags(cmd.Flags())
return cmd
}
func main() {
rootCmd := newRootCmd()
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}