feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端

来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 11:20:04 +08:00
co-authored by Claude Opus 4.7
parent 99a4854def
commit 85c0071fd8
653 changed files with 85000 additions and 0 deletions
@@ -0,0 +1,50 @@
package reptilerecord
import (
"hkdj-web-server/pub/common/ipaddr"
"hkdj-web-server/pub/common/log"
"strings"
"github.com/gin-gonic/gin"
)
const ctxKeyIsBot = "isBot"
var (
botPatterns = map[string]string{
"Googlebot": "Googlebot",
"Bingbot": "Bingbot",
"Slurp": "Slurp",
"DuckDuckBot": "DuckDuckBot",
"Baiduspider": "Baiduspider",
"YandexBot": "YandexBot",
"Sogou": "Sogou",
"Exabot": "Exabot",
"facebot": "facebot",
"facebookexternalhit": "facebookexternalhit",
}
)
func ReptileRecord(c *gin.Context) {
ua := c.Request.UserAgent()
botName := identifyBot(ua)
if botName != "" {
c.Set(ctxKeyIsBot, true)
log.Info("爬虫访问:", log.Any("botName", botName), log.Any("ua", ua), log.Any("path", c.Request.URL.Path), log.Any("ip", ipaddr.ResolveClientIP(c)))
}
}
// IsBot 返回当前请求是否来自已知搜索引擎爬虫
func IsBot(c *gin.Context) bool {
v, exists := c.Get(ctxKeyIsBot)
return exists && v.(bool)
}
func identifyBot(userAgent string) string {
for name, pattern := range botPatterns {
if strings.Contains(userAgent, pattern) {
return name
}
}
return ""
}