feat: complete remaining Go backend modules
This commit is contained in:
1 parent
cea2751dc5
commit
aef5a97165
145 files changed
+18376
-199
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/application"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/settings"
|
||||
)
|
||||
|
||||
const shutdownTimeout = 10 * time.Second
|
||||
@@ -28,14 +29,18 @@ func run() error {
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
app, err := application.New(application.Options{Context: ctx})
|
||||
getenv, err := runtimeGetenv(os.Getenv)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load Go backend runtime settings: %w", err)
|
||||
}
|
||||
app, err := application.New(application.Options{Context: ctx, Getenv: getenv})
|
||||
if err != nil {
|
||||
return fmt.Errorf("initialize Go backend: %w", err)
|
||||
}
|
||||
defer app.Close()
|
||||
|
||||
server := &http.Server{
|
||||
Addr: listenAddress(os.Getenv),
|
||||
Addr: listenAddress(getenv),
|
||||
Handler: app.Handler(),
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
}
|
||||
@@ -66,6 +71,29 @@ func run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func runtimeGetenv(process func(string) string) (func(string) string, error) {
|
||||
path := strings.TrimSpace(process("ZHINIAN_SETTINGS_FILE"))
|
||||
if path == "" {
|
||||
path = ".env.local"
|
||||
}
|
||||
values := map[string]string{}
|
||||
for _, key := range settings.RuntimeSettingKeys() {
|
||||
if value := process(key); value != "" {
|
||||
values[key] = value
|
||||
}
|
||||
}
|
||||
merged, err := settings.LoadEnvironment(path, values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return func(name string) string {
|
||||
if value, exists := merged[name]; exists {
|
||||
return value
|
||||
}
|
||||
return process(name)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func listenAddress(getenv func(string) string) string {
|
||||
host := strings.TrimSpace(getenv("GO_BACKEND_HOST"))
|
||||
if host == "" {
|
||||
|
||||
Reference in new issue
Block a user