-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
89 lines (76 loc) · 2.48 KB
/
main.go
File metadata and controls
89 lines (76 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"flag"
"fmt"
"log"
"os"
"go-analyzer/api_service"
"go-analyzer/domain/analysis"
"go-analyzer/domain/demo"
"go-analyzer/domain/requirements"
"go-analyzer/repo"
"go-analyzer/shared"
)
func main() {
var (
mode = flag.String("mode", "cli", "Mode to run: cli or web")
repoURL = flag.String("repo", "", "GitHub repository URL to analyze (CLI mode)")
configPath = flag.String("config", "config/config.yaml", "Path to configuration file")
webPort = flag.String("port", "", "Web server port (overrides config)")
)
flag.Parse()
// Load configuration from YAML file
config, err := shared.LoadConfig(*configPath)
if err != nil {
log.Printf("Warning: Could not load config file %s: %v", *configPath, err)
log.Println("Using default configuration...")
config = shared.DefaultConfig()
}
// Override web port if provided via command line
if *webPort != "" {
config.Web.Port = *webPort
}
// Initialize repository factory
repoFactory := repo.NewRepositoryFactory(
config.Database.Neo4j.URI,
config.Database.Neo4j.Username,
config.Database.Neo4j.Password,
)
// Initialize domain services
analyzer := analysis.NewAnalyzer(config, repoFactory)
reqProcessor := requirements.NewRequirementProcessor(config)
demoGenerator := demo.NewDemoGenerator(repoFactory, config)
switch *mode {
case "web":
fmt.Printf("Starting Go Analyzer Web Interface on port %s\n", config.Web.Port)
fmt.Printf("Neo4j connection: %s\n", config.Database.Neo4j.URI)
fmt.Printf("Open http://localhost:%s in your browser\n", config.Web.Port)
// Test Neo4j connection
if err := repoFactory.Connect(); err != nil {
log.Fatalf("Failed to connect to Neo4j: %v", err)
}
// Close test connection - each analysis will create its own connection
repoFactory.Close()
// Start web server with domain services
server := api_service.NewWebServer(analyzer, reqProcessor, demoGenerator, config.Web.Port)
if err := server.Start(); err != nil {
log.Fatalf("Web server failed: %v", err)
}
case "cli":
if *repoURL == "" {
fmt.Println("CLI Usage: go run . -mode cli -repo <github-url>")
fmt.Println("Web Usage: go run . -mode web")
flag.PrintDefaults()
os.Exit(1)
}
fmt.Printf("Analyzing repository: %s\n", *repoURL)
if err := analyzer.AnalyzeRepository(*repoURL); err != nil {
log.Fatalf("Analysis failed: %v", err)
}
fmt.Println("Analysis completed successfully!")
default:
fmt.Printf("Unknown mode: %s\n", *mode)
flag.PrintDefaults()
os.Exit(1)
}
}