From d6f2e4d430e0a87908dc9499067c7a39467f6f77 Mon Sep 17 00:00:00 2001 From: kongfei605 Date: Fri, 16 Jun 2023 18:27:52 +0800 Subject: [PATCH] Appdynamics update (#544) * add labels for appdynamics * update configure for appdynamics * snakecase update --- conf/input.appdynamics/app.toml | 2 +- pkg/stringx/strx.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/conf/input.appdynamics/app.toml b/conf/input.appdynamics/app.toml index d4c61e9b..eedb65eb 100644 --- a/conf/input.appdynamics/app.toml +++ b/conf/input.appdynamics/app.toml @@ -9,7 +9,7 @@ # # 指定url_vars中哪些key 作为最终的label附加 # url_var_label_keys= [] -# #从url中提取变量 +# #从url中提取变量 # url_label_key="instance" # url_label_value="{{.Host}}" # #自定义 http header diff --git a/pkg/stringx/strx.go b/pkg/stringx/strx.go index 10d8c260..2997d990 100644 --- a/pkg/stringx/strx.go +++ b/pkg/stringx/strx.go @@ -13,9 +13,15 @@ func SnakeCase(in string) string { if runes[i] == '.' { continue } - if i > 0 && unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) { - if runes[i-1] != '_' { - out = append(out, '_') + if i > 0 { + if (runes[i] == '_' && runes[i-1] == '_') || + (i == length-1 && runes[i] == '_') { + continue + } + if unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) { + if runes[i-1] != '_' { + out = append(out, '_') + } } } out = append(out, unicode.ToLower(runes[i]))