From 06c9858866a8866987be18d95c28e585c8c80229 Mon Sep 17 00:00:00 2001 From: nitezs Date: Thu, 21 Sep 2023 17:37:37 +0800 Subject: [PATCH] =?UTF-8?q?modify:=20=E5=A2=9E=E5=8A=A0debug=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/default.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api/controller/default.go b/api/controller/default.go index 0b58d97..2c561aa 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -4,11 +4,13 @@ import ( "crypto/sha256" "encoding/hex" "errors" + "go.uber.org/zap" "gopkg.in/yaml.v3" "net/url" "regexp" "sort" "strings" + "sub2clash/logger" "sub2clash/model" "sub2clash/parser" "sub2clash/utils" @@ -31,17 +33,24 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template if err != nil { templateBytes, err = utils.LoadTemplate(template) if err != nil { + logger.Logger.Debug( + "load template failed", zap.String("template", template), zap.Error(err), + ) return nil, errors.New("加载模板失败: " + err.Error()) } } else { templateBytes, err = utils.LoadSubscription(template, query.Refresh) if err != nil { + logger.Logger.Debug( + "load template failed", zap.String("template", template), zap.Error(err), + ) return nil, errors.New("加载模板失败: " + err.Error()) } } // 解析模板 err = yaml.Unmarshal(templateBytes, &temp) if err != nil { + logger.Logger.Debug("parse template failed", zap.Error(err)) return nil, errors.New("解析模板失败: " + err.Error()) } var proxyList []model.Proxy @@ -49,10 +58,12 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template for i := range query.Subs { data, err := utils.LoadSubscription(query.Subs[i], query.Refresh) if err != nil { + logger.Logger.Debug( + "load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err), + ) return nil, errors.New("加载订阅失败: " + err.Error()) } // 解析订阅 - err = yaml.Unmarshal(data, &sub) if err != nil { reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|http|https)://") @@ -63,6 +74,11 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template // 如果无法直接解析,尝试Base64解码 base64, err := parser.DecodeBase64(string(data)) if err != nil { + logger.Logger.Debug( + "parse subscription failed", zap.String("url", query.Subs[i]), + zap.String("data", string(data)), + zap.Error(err), + ) return nil, errors.New("加载订阅失败: " + err.Error()) } p := utils.ParseProxy(strings.Split(base64, "\n")...)