From 4276709b3f82e50b2f836c4ec179e135a41894a4 Mon Sep 17 00:00:00 2001 From: wood chen Date: Sun, 9 Mar 2025 05:47:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(config):=20=E6=B7=BB=E5=8A=A0=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E4=BF=9D=E5=AD=98=E9=97=B4=E9=9A=94=E5=92=8C=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=96=87=E4=BB=B6=E6=95=B0=E7=9A=84=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在配置解析中新增 MetricsSaveInterval 和 MetricsMaxFiles 字段 - 在前端页面为指标配置添加默认值(15分钟间隔,10个文件) - 更新配置解析逻辑以支持新的指标相关配置 --- internal/config/types.go | 14 +++++++++----- web/app/dashboard/config/page.tsx | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/config/types.go b/internal/config/types.go index fb74809..16e4cda 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -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 } diff --git a/web/app/dashboard/config/page.tsx b/web/app/dashboard/config/page.tsx index b29abff..58205b3 100644 --- a/web/app/dashboard/config/page.tsx +++ b/web/app/dashboard/config/page.tsx @@ -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 : "获取配置失败"