init: web_hgdjc_server

This commit is contained in:
2026-11-07 10:44:09 +08:00
commit 71a4f4e175
713 changed files with 147749 additions and 0 deletions
@@ -0,0 +1,50 @@
package reptilerecord
import (
"strings"
"videoweb/pub/common/ipaddr"
"videoweb/pub/common/log"
"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 ""
}