aboutsummaryrefslogtreecommitdiff
path: root/user_agent.go
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2020-02-14 09:24:29 +0000
committerFelix Hanley <felix@userspace.com.au>2020-02-14 09:24:29 +0000
commitbd8968313b3145828822bdd7e12a6e5aa2896c15 (patch)
tree198868c13e1e21d5cea665f87d3f3cb58d432072 /user_agent.go
parent729c39874d906a6312b878046ca24458af4b6a8b (diff)
downloadsws-bd8968313b3145828822bdd7e12a6e5aa2896c15.tar.gz
sws-bd8968313b3145828822bdd7e12a6e5aa2896c15.tar.bz2
Fix template loading order
Diffstat (limited to 'user_agent.go')
-rw-r--r--user_agent.go9
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)))
}