mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 08:31:55 +08:00
feat(config): 添加指标保存间隔和最大文件数的默认值处理
- 在配置解析中新增 MetricsSaveInterval 和 MetricsMaxFiles 字段 - 在前端页面为指标配置添加默认值(15分钟间隔,10个文件) - 更新配置解析逻辑以支持新的指标相关配置
This commit is contained in:
parent
015aa6bc15
commit
4276709b3f
@ -35,8 +35,10 @@ type CompressorConfig struct {
|
||||
func (c *Config) UnmarshalJSON(data []byte) error {
|
||||
// 创建一个临时结构来解析原始JSON
|
||||
type TempConfig struct {
|
||||
MAP map[string]json.RawMessage `json:"MAP"`
|
||||
Compression CompressionConfig `json:"Compression"`
|
||||
MAP map[string]json.RawMessage `json:"MAP"`
|
||||
Compression CompressionConfig `json:"Compression"`
|
||||
MetricsSaveInterval int `json:"MetricsSaveInterval"`
|
||||
MetricsMaxFiles int `json:"MetricsMaxFiles"`
|
||||
}
|
||||
|
||||
var temp TempConfig
|
||||
@ -47,6 +49,11 @@ func (c *Config) UnmarshalJSON(data []byte) error {
|
||||
// 初始化 MAP
|
||||
c.MAP = make(map[string]PathConfig)
|
||||
|
||||
// 复制其他字段
|
||||
c.Compression = temp.Compression
|
||||
c.MetricsSaveInterval = temp.MetricsSaveInterval
|
||||
c.MetricsMaxFiles = temp.MetricsMaxFiles
|
||||
|
||||
// 处理每个路径配置
|
||||
for key, raw := range temp.MAP {
|
||||
// 尝试作为字符串解析
|
||||
@ -69,9 +76,6 @@ func (c *Config) UnmarshalJSON(data []byte) error {
|
||||
c.MAP[key] = pathConfig
|
||||
}
|
||||
|
||||
// 复制其他字段
|
||||
c.Compression = temp.Compression
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,16 @@ export default function ConfigPage() {
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
// 设置默认值
|
||||
if (data.MetricsSaveInterval === undefined || data.MetricsSaveInterval === 0) {
|
||||
data.MetricsSaveInterval = 15; // 默认15分钟
|
||||
}
|
||||
|
||||
if (data.MetricsMaxFiles === undefined || data.MetricsMaxFiles === 0) {
|
||||
data.MetricsMaxFiles = 10; // 默认10个文件
|
||||
}
|
||||
|
||||
setConfig(data)
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "获取配置失败"
|
||||
|
Loading…
x
Reference in New Issue
Block a user