-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (51 loc) · 1.46 KB
/
Copy pathmain.go
File metadata and controls
61 lines (51 loc) · 1.46 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/ja1code/quicrawl/internal/cli"
"github.com/ja1code/quicrawl/internal/http"
"github.com/ja1code/quicrawl/internal/service"
)
func main() {
var (
mode = flag.String("mode", "cli", "Mode to run in: 'server' or 'cli'")
port = flag.Int("port", 8080, "Port for HTTP server (only used in server mode)")
)
flag.Parse()
// Create service instance
svc := service.New()
switch *mode {
case "server":
runServer(svc, *port)
case "cli":
runCLI(svc)
default:
fmt.Printf("Invalid mode: %s. Use 'server' or 'cli'\n", *mode)
os.Exit(1)
}
}
func runServer(svc *service.Service, port int) {
server := http.NewServer(svc, port)
fmt.Printf("Starting HTTP server on port %d...\n", port)
fmt.Println("Available endpoints:")
fmt.Println(" GET / - API info")
fmt.Println(" POST /api/v1/process - Process input")
fmt.Println(" POST /api/v1/crawl - Crawl website")
fmt.Println(" POST /api/v1/crawl-parallel - Crawl website and links in parallel")
fmt.Println(" GET /api/v1/config - Get service configuration")
fmt.Println(" GET /api/v1/status - Get service status")
fmt.Println(" GET /api/v1/health - Health check")
fmt.Println("Press Ctrl+C to stop")
if err := server.Start(); err != nil {
log.Fatalf("Server failed to start: %v", err)
}
}
func runCLI(svc *service.Service) {
cliApp := cli.NewCLI(svc)
if err := cliApp.Execute(); err != nil {
// Error is already printed by cobra
os.Exit(1)
}
}