From f79aecf5ef81ce3e01553aa4aff8c6ec824230d4 Mon Sep 17 00:00:00 2001 From: yiqiwang-17 <66986742+yiqiwang-17@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:17:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9meta=E6=96=87=E4=BB=B6?= =?UTF-8?q?key=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/task.go | 9 ++++++++- config/task_test.go | 12 +++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config/task.go b/config/task.go index d4c15e6..64f3f01 100644 --- a/config/task.go +++ b/config/task.go @@ -92,6 +92,12 @@ type SenderConfig struct { OutputFormat string `config:"output_format"` // 输出格式,为了兼容老版采集器的输出格式 } +func metaKeyToField(key string) string { + metaKey := strings.ReplaceAll(key, "/", "_") + metaKey = strings.ReplaceAll(metaKey, ".", "_") + return strings.ReplaceAll(metaKey, "-", "_") +} + func loadMetaFile(p string) map[string]string { b, err := os.ReadFile(p) if err != nil { @@ -108,7 +114,8 @@ func loadMetaFile(p string) map[string]string { } v := strings.Trim(strings.TrimSpace(parts[1]), `"`) - meta[strings.TrimSpace(parts[0])] = v + k := metaKeyToField(strings.TrimSpace(parts[0])) + meta[k] = v } return meta } diff --git a/config/task_test.go b/config/task_test.go index d88e989..35a2747 100644 --- a/config/task_test.go +++ b/config/task_test.go @@ -58,6 +58,7 @@ k2="v2" k3 = "v3" k4= "v4" k5= "v5=foo" +k5.test/gt-hh= "test" # foobar `) @@ -67,11 +68,12 @@ foobar meta := loadMetaFile(f.Name()) excepted := map[string]string{ - "k1": "v1", - "k2": "v2", - "k3": "v3", - "k4": "v4", - "k5": "v5=foo", + "k1": "v1", + "k2": "v2", + "k3": "v3", + "k4": "v4", + "k5": "v5=foo", + "k5_test_gt_hh": "test", } assert.Equal(t, excepted, meta)