From 0648f61e9cab8ba179ad4d2e9593ab1337a32e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A6=86=E6=9C=A8?= <43062104+yumusb@users.noreply.github.com> Date: Wed, 4 Dec 2024 20:00:35 +0800 Subject: [PATCH] Update waf.go (#548) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WAF查询IP是否被封禁导致控制台大量报错,换一个查询方式。 --- model/waf.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/model/waf.go b/model/waf.go index af28469d5b..63f50327d2 100644 --- a/model/waf.go +++ b/model/waf.go @@ -43,10 +43,12 @@ func CheckIP(db *gorm.DB, ip string) error { return err } var w WAF - if err := db.First(&w, "ip = ?", ipBinary).Error; err != nil { - if err != gorm.ErrRecordNotFound { - return err - } + result := db.Limit(1).Find(&w, "ip = ?", ipBinary) + if result.Error != nil { + return result.Error + } + if result.RowsAffected == 0 { // 检查是否未找到记录 + return nil } now := time.Now().Unix() if powAdd(w.Count, 4, w.LastBlockTimestamp) > uint64(now) {