From 9a6a73cae578f21e0ce351557551f5ad4bc77139 Mon Sep 17 00:00:00 2001 From: liuxiaobo <1224730913@qq.com> Date: Sat, 31 May 2025 08:40:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dksync.go=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=BE=97=E5=B4=A9=E6=BA=83=E7=89=B9=E5=BE=81?= =?UTF-8?q?=E7=A0=81=E6=9C=89=E5=8F=AF=E8=83=BD=E5=B9=B6=E5=8F=91=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E9=97=AE=E9=A2=98lastAttributeCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ksync/ksync.go | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/ksync/ksync.go b/ksync/ksync.go index 2b8ab74..6e685f0 100644 --- a/ksync/ksync.go +++ b/ksync/ksync.go @@ -5,29 +5,28 @@ import ( "github.com/fox/fox/log" "github.com/wanghuiyt/ding" "runtime/debug" - "strings" ) // 辅助函数列表 var ( - DingAccessToken = "" // 钉钉token - DingSecret = "" // 钉钉加签 - lastAttributeCode = "" // 最近一条error信息 + DingAccessToken = "" // 钉钉token + DingSecret = "" // 钉钉加签 + //lastAttributeCode = "" // 最近一条error信息 ) -func getAttributeCode(stackErr string) string { - lines := strings.Split(stackErr, "\n") - // 检查是否有足够的行数,并提取第9行(索引为8,因为索引从0开始) - if len(lines) >= 9 { - goIndex := strings.LastIndex(lines[8], ".go") - if goIndex != -1 { - filteredStr := lines[8][:goIndex] - filteredStr = strings.TrimLeft(filteredStr, "\t ") - return filteredStr - } - } - return "" -} +//func getAttributeCode(stackErr string) string { +// lines := strings.Split(stackErr, "\n") +// // 检查是否有足够的行数,并提取第9行(索引为8,因为索引从0开始) +// if len(lines) >= 9 { +// goIndex := strings.LastIndex(lines[8], ".go") +// if goIndex != -1 { +// filteredStr := lines[8][:goIndex] +// filteredStr = strings.TrimLeft(filteredStr, "\t ") +// return filteredStr +// } +// } +// return "" +//} // 发送消息给钉钉 func sendMessage(msg interface{}, stackErr string, dingToken, dingSecret string) { @@ -43,13 +42,13 @@ func sendMessage(msg interface{}, stackErr string, dingToken, dingSecret string) func Recover(recoverFunc func()) { if msg := recover(); msg != nil { stackErr := string(debug.Stack()) - attributeCode := getAttributeCode(stackErr) - if lastAttributeCode != attributeCode { - lastAttributeCode = attributeCode - log.ErrorF("Recover panic:%v", msg) - log.Error(stackErr) - sendMessage(msg, stackErr, DingAccessToken, DingSecret) - } + //attributeCode := getAttributeCode(stackErr) + //if lastAttributeCode != attributeCode { + // lastAttributeCode = attributeCode + log.ErrorF("Recover panic:%v", msg) + log.Error(stackErr) + sendMessage(msg, stackErr, DingAccessToken, DingSecret) + //} if recoverFunc != nil { recoverFunc() }