-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
84 lines (74 loc) · 2.58 KB
/
Copy pathmain.go
File metadata and controls
84 lines (74 loc) · 2.58 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
// main.go dispatches the process-level Athena commands and keeps the repository entry thin.
// main.go 负责分发 Athena 的进程级命令,并保持仓库入口层足够薄。
package main
import (
"context"
"fmt"
"log"
"os"
"gitee.com/super_sky/mkh_utils"
"moss/internal/config"
"moss/internal/entry"
)
// main dispatches the lightweight athena process commands without changing the repository layering.
// main 会在不破坏仓库分层的前提下分发 athena 的轻量进程命令。
func main() {
mkh_utils.CheckVersion()
command := "api-server"
if len(os.Args) > 1 {
command = os.Args[1]
}
switch command {
case "version":
fmt.Print(entry.VersionString())
return
case "healthcheck":
cfg, err := config.LoadFromEnv()
if err != nil {
log.Fatalf("failed to load config: %v", err)
}
runHealthcheck(cfg)
case "api-server":
cfg, err := config.LoadFromEnv()
if err != nil {
log.Fatalf("failed to load config: %v", err)
}
runAPIServer(cfg)
case "migrate":
cfg, err := config.LoadFromEnv()
if err != nil {
log.Fatalf("failed to load config: %v", err)
}
runMigrate(cfg)
default:
log.Fatalf("unsupported command %q, expected one of: api-server, migrate, healthcheck, version", command)
}
}
// runAPIServer starts the HTTP service using the configured entry graph.
// runAPIServer 会通过当前配置好的 entry 依赖图启动 HTTP 服务。
func runAPIServer(cfg config.Config) {
appEntry, err := entry.New(cfg)
if err != nil {
log.Fatalf("failed to build entry: %v", err)
}
appEntry.Startup(context.Background())
log.Printf("Starter service listening on http://localhost:%d", cfg.Server.HTTPPort)
log.Printf("Health check: curl http://localhost:%d/healthz", cfg.Server.HTTPPort)
log.Printf("Stream chat: curl -N -X POST http://localhost:%d/api/chat/stream -H 'Content-Type: application/json' -d '{\"query\":\"hello\"}'", cfg.Server.HTTPPort)
appEntry.Server.Spin()
}
// runMigrate executes the configured session-store migration path.
// runMigrate 会执行当前 session store 的 migrate 路径。
func runMigrate(cfg config.Config) {
if err := entry.MigrateStores(context.Background(), cfg); err != nil {
log.Fatalf("migrate failed: %v", err)
}
log.Printf("storage migrate finished successfully")
}
// runHealthcheck probes the local health endpoint so container runtimes do not need curl inside the image.
// runHealthcheck 会探测本地 health endpoint,避免容器运行时必须内置 curl。
func runHealthcheck(cfg config.Config) {
if err := entry.RunHealthcheck(cfg); err != nil {
log.Fatalf("healthcheck failed: %v", err)
}
}