feat(proxy): 支持品赞分组代理与自动白名单
This commit is contained in:
@@ -174,6 +174,7 @@ func defaultConfig() types.Config {
|
||||
RetryStages: defaultRetryStages(),
|
||||
SeckillMode: types.SeckillModeAggressive,
|
||||
XiaodianPageSize: 200,
|
||||
AccountsPerProxy: constants.DefaultAccountsPerProxy,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,11 +229,21 @@ func LoadConfig(path string) types.Config {
|
||||
if len(cfg.RetryStages) == 0 {
|
||||
cfg.RetryStages = defaultRetryStages()
|
||||
}
|
||||
normalizeProxyConfig(&cfg)
|
||||
normalizeXiaodianConfig(&cfg)
|
||||
logger.LogEvent("配置", "success", "配置加载完成: %s", path)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func normalizeProxyConfig(cfg *types.Config) {
|
||||
if cfg.AccountsPerProxy <= 0 {
|
||||
cfg.AccountsPerProxy = constants.DefaultAccountsPerProxy
|
||||
}
|
||||
if cfg.AccountsPerProxy > constants.MaxAccountsPerProxy {
|
||||
cfg.AccountsPerProxy = constants.MaxAccountsPerProxy
|
||||
}
|
||||
}
|
||||
|
||||
// normalizeXiaodianConfig 约束和平小店分页参数,接口单页最大为 200。
|
||||
func normalizeXiaodianConfig(cfg *types.Config) {
|
||||
if cfg.XiaodianPageSize <= 0 || cfg.XiaodianPageSize > 200 {
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"douyu_go/internal/constants"
|
||||
)
|
||||
|
||||
func TestMigrateLegacyFile(t *testing.T) {
|
||||
@@ -110,3 +112,19 @@ func TestExplicitLogDirOverridesWailsDev(t *testing.T) {
|
||||
t.Fatalf("显式日志目录 = %q, want %q", paths.LogDir, customLogDir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfigNormalizesAccountsPerProxy(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.json")
|
||||
if err := os.WriteFile(path, []byte(`{"accountsPerProxy":0}`), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := LoadConfig(path).AccountsPerProxy; got != constants.DefaultAccountsPerProxy {
|
||||
t.Fatalf("AccountsPerProxy=%d, want %d", got, constants.DefaultAccountsPerProxy)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(`{"accountsPerProxy":999}`), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := LoadConfig(path).AccountsPerProxy; got != constants.MaxAccountsPerProxy {
|
||||
t.Fatalf("AccountsPerProxy=%d, want %d", got, constants.MaxAccountsPerProxy)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user