feat: enable configured multitable synchronization

This commit is contained in:
Eric 1549169735@qq.com
2026-08-19 22:19:51 +08:00
parent 1e3434d76e
commit 11ae6761ad
5 changed files with 51 additions and 38 deletions

View File

@@ -137,14 +137,6 @@ func Load(options LoadOptions) (Config, error) {
if environment != "" {
cfg.App.Env = environment
}
if cfg.App.Env == "prod" {
if strings.TrimSpace(os.Getenv("APP_DATABASE_PASSWORD")) == "" {
return Config{}, errors.New("APP_DATABASE_PASSWORD must be set in production")
}
if strings.TrimSpace(os.Getenv("APP_AUTH_JWT_SECRET")) == "" {
return Config{}, errors.New("APP_AUTH_JWT_SECRET must be set in production")
}
}
if err := cfg.Validate(); err != nil {
return Config{}, err
}
@@ -187,7 +179,7 @@ func (c Config) Validate() error {
return errors.New("multitable.base_url must use https when multitable is enabled")
}
if strings.TrimSpace(c.MultiTable.APIKey) == "" {
return errors.New("APP_MULTITABLE_API_KEY is required when multitable is enabled")
return errors.New("multitable.api_key is required when multitable is enabled")
}
if c.MultiTable.SyncInterval <= 0 || c.MultiTable.RequestTimeout <= 0 || c.MultiTable.BatchSize < 1 || c.MultiTable.MaxAttempts < 1 {
return errors.New("multitable retry and timeout settings must be positive")

View File

@@ -3,7 +3,6 @@ package config
import (
"os"
"path/filepath"
"strings"
"testing"
)
@@ -69,24 +68,14 @@ database:
}
}
func TestLoadProductionRequiresEnvironmentSecrets(t *testing.T) {
dir := writeConfigs(t, "app:\n env: production\n")
t.Setenv("APP_DATABASE_PASSWORD", "")
t.Setenv("APP_AUTH_JWT_SECRET", "")
_, err := Load(LoadOptions{Environment: "prod", ConfigDir: dir})
if err == nil || !strings.Contains(err.Error(), "APP_DATABASE_PASSWORD") {
t.Fatalf("Load() error = %v, want production password requirement", err)
}
t.Setenv("APP_DATABASE_PASSWORD", "production-password")
t.Setenv("APP_AUTH_JWT_SECRET", "production-jwt-secret")
func TestLoadProductionSecretsFromConfig(t *testing.T) {
dir := writeConfigs(t, "app:\n env: production\ndatabase:\n password: production-password\nauth:\n jwt_secret: production-jwt-secret\n")
cfg, err := Load(LoadOptions{Environment: "prod", ConfigDir: dir})
if err != nil {
t.Fatalf("Load() with environment secrets error = %v", err)
t.Fatalf("Load() with config secrets error = %v", err)
}
if cfg.Database.Password != "production-password" || cfg.Auth.JWTSecret != "production-jwt-secret" {
t.Fatalf("environment secrets were not applied")
t.Fatalf("config secrets were not applied")
}
}