feat: implement comprehensive configuration validation and integrate into store loading and server initialization.

This commit is contained in:
CJACK
2026-04-05 21:18:51 +08:00
parent 585d35e592
commit a28c9fb67f
11 changed files with 299 additions and 60 deletions

View File

@@ -3,6 +3,7 @@ package server
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
@@ -29,8 +30,11 @@ type App struct {
Router http.Handler
}
func NewApp() *App {
store := config.LoadStore()
func NewApp() (*App, error) {
store, err := config.LoadStoreWithError()
if err != nil {
return nil, fmt.Errorf("load config: %w", err)
}
pool := account.NewPool(store)
var dsClient *deepseek.Client
resolver := auth.NewResolver(store, pool, func(ctx context.Context, acc config.Account) (string, error) {
@@ -85,7 +89,7 @@ func NewApp() *App {
http.NotFound(w, req)
})
return &App{Store: store, Pool: pool, Resolver: resolver, DS: dsClient, Router: r}
return &App{Store: store, Pool: pool, Resolver: resolver, DS: dsClient, Router: r}, nil
}
func timeout(d time.Duration) func(http.Handler) http.Handler {

View File

@@ -7,7 +7,13 @@ import (
)
func TestHealthEndpointsSupportHEAD(t *testing.T) {
app := NewApp()
t.Setenv("DS2API_CONFIG_JSON", `{"keys":["k1"],"accounts":[{"email":"u@example.com","password":"p"}]}`)
t.Setenv("DS2API_ENV_WRITEBACK", "0")
app, err := NewApp()
if err != nil {
t.Fatalf("NewApp() error: %v", err)
}
for _, path := range []string{"/healthz", "/readyz"} {
req := httptest.NewRequest(http.MethodHead, path, nil)