Add bots documentation

This commit is contained in:
Matt Baer
2015-07-07 02:35:17 -04:00
parent 17007ee930
commit d01e265587
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -1,3 +1,6 @@
// This package helps the backend determine which clients are bots or crawlers.
// In Write.as, this is used to prevent certain things when viewing posts, like
// incrementing the view count.
package bots package bots
var bots = map[string]bool{ var bots = map[string]bool{
@@ -26,6 +29,8 @@ var bots = map[string]bool{
"Twitterbot/1.0": true, "Twitterbot/1.0": true,
} }
// IsBot returns whether or not the provided User-Agent string is a known bot
// or crawler.
func IsBot(ua string) bool { func IsBot(ua string) bool {
if _, ok := bots[ua]; ok { if _, ok := bots[ua]; ok {
return true return true
+5
View File
@@ -9,6 +9,9 @@ cat /var/log/$1 | grep -i bot | awk -F\" '{print $4}' | sort | uniq > bots.txt
rm bots.go rm bots.go
cat > bots.go << EOM cat > bots.go << EOM
// This package helps the backend determine which clients are bots or crawlers.
// In Write.as, this is used to prevent certain things when viewing posts, like
// incrementing the view count.
package bots package bots
var bots = map[string]bool { var bots = map[string]bool {
@@ -23,6 +26,8 @@ done <bots.txt
cat >> bots.go << EOM cat >> bots.go << EOM
}; };
// IsBot returns whether or not the provided User-Agent string is a known bot
// or crawler.
func IsBot(ua string) bool { func IsBot(ua string) bool {
if _, ok := bots[ua]; ok { if _, ok := bots[ua]; ok {
return true return true