forked from tbphp/gpt-load
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (57 loc) · 1.83 KB
/
Copy pathmain.go
File metadata and controls
70 lines (57 loc) · 1.83 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
// Package main provides the entry point for the GPT-Load proxy server
package main
import (
"context"
"embed"
"os"
"os/signal"
"syscall"
"time"
"gpt-load/internal/app"
"gpt-load/internal/container"
"gpt-load/internal/types"
"gpt-load/internal/utils"
"github.com/sirupsen/logrus"
)
//go:embed web/dist
var buildFS embed.FS
//go:embed web/dist/index.html
var indexPage []byte
func main() {
// Build the dependency injection container
container, err := container.BuildContainer()
if err != nil {
logrus.Fatalf("Failed to build container: %v", err)
}
// Provide UI assets to the container
if err := container.Provide(func() embed.FS { return buildFS }); err != nil {
logrus.Fatalf("Failed to provide buildFS: %v", err)
}
if err := container.Provide(func() []byte { return indexPage }); err != nil {
logrus.Fatalf("Failed to provide indexPage: %v", err)
}
// Initialzie global logger
if err := container.Invoke(func(configManager types.ConfigManager) {
utils.SetupLogger(configManager)
}); err != nil {
logrus.Fatalf("Failed to setup logger: %v", err)
}
// Create and run the application
if err := container.Invoke(func(application *app.App, configManager types.ConfigManager) {
if err := application.Start(); err != nil {
logrus.Fatalf("Failed to start application: %v", err)
}
// Wait for interrupt signal for graceful shutdown
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
// Create a context with timeout for shutdown
serverConfig := configManager.GetEffectiveServerConfig()
shutdownCtx, cancel := context.WithTimeout(context.Background(), time.Duration(serverConfig.GracefulShutdownTimeout)*time.Second)
defer cancel()
// Perform graceful shutdown
application.Stop(shutdownCtx)
}); err != nil {
logrus.Fatalf("Failed to run application: %v", err)
}
}