- 48 个 Go 文件所有注释(行注释/块注释/行尾注释,含 _test.go)翻译为中文 - 保留技术标识符:SECURITY_TODO(n)、unsafe-inline、sqlite/mysql、路由参数等 - 代码、字符串字面量、日志消息保持英文原文,零逻辑改动 - go build/vet 通过,go test -count=1 ./... 全绿
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package models
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// botPatterns 包含常见的 bot/爬虫/蜘蛛 User-Agent 特征模式。
|
|
var botPatterns = []string{
|
|
"bot", "crawler", "spider", "scraper", "scraping",
|
|
"googlebot", "bingbot", "baiduspider", "yandexbot",
|
|
"duckduckbot", "slurp", "teoma", "ia_archiver",
|
|
"facebookexternalhit", "facebot", "twitterbot",
|
|
"whatsapp", "telegram", "slackbot", "discordbot",
|
|
"linkedinbot", "pinterestbot", "tumblr",
|
|
"semrushbot", "ahrefsbot", "mj12bot", "dotbot",
|
|
"archive.org_bot", "serpstatbot", "dataforseo",
|
|
"petalbot", "gptbot", "claudebot", "anthropic-ai",
|
|
"bytespider", "applebot", "seznambot",
|
|
"headless", "phantom", "selenium", "puppeteer",
|
|
}
|
|
|
|
// IsBot 检查给定的 User-Agent 字符串是否匹配已知的 bot 特征模式。
|
|
// 它针对常见的 bot 标识进行不区分大小写的子串匹配。
|
|
func IsBot(userAgent string) bool {
|
|
if userAgent == "" {
|
|
return false
|
|
}
|
|
|
|
ua := strings.ToLower(userAgent)
|
|
|
|
for _, pattern := range botPatterns {
|
|
if strings.Contains(ua, pattern) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|