diff options
| author | Felix Hanley <felix@userspace.com.au> | 2020-02-14 09:24:29 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2020-02-14 09:24:29 +0000 |
| commit | bd8968313b3145828822bdd7e12a6e5aa2896c15 (patch) | |
| tree | 198868c13e1e21d5cea665f87d3f3cb58d432072 /user_agent.go | |
| parent | 729c39874d906a6312b878046ca24458af4b6a8b (diff) | |
| download | sws-bd8968313b3145828822bdd7e12a6e5aa2896c15.tar.gz sws-bd8968313b3145828822bdd7e12a6e5aa2896c15.tar.bz2 | |
Fix template loading order
Diffstat (limited to 'user_agent.go')
| -rw-r--r-- | user_agent.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/user_agent.go b/user_agent.go index cbb831b..19973b3 100644 --- a/user_agent.go +++ b/user_agent.go @@ -4,15 +4,24 @@ import ( "crypto/sha1" "fmt" "net/http" + "regexp" "time" ) +var botRegex = regexp.MustCompile("(?i)(bot|crawler|sp(i|y)der|search|worm|fetch|nutch)") +var botFromSiteRegexp = regexp.MustCompile("http[s]?://.+\\.\\w+") + type UserAgent struct { Hash string `json:"hash"` Name string `json:"name"` LastSeenAt time.Time `json:"last_seen_at"` } +func (ua UserAgent) Bot() bool { + // TODO a little naive ATM + return botRegex.MatchString(ua.Name) || botFromSiteRegexp.MatchString(ua.Name) +} + func UserAgentHash(s string) string { return fmt.Sprintf("%x", sha1.Sum([]byte(s))) } |
