mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-16 22:25:15 +08:00
feat: implement comprehensive configuration validation and integrate into store loading and server initialization.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user