isbot

package module
v0.0.0-...-7726dc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 4 Imported by: 0

README

IsBot

Detect bots/crawlers/spiders using the user agent string.

Using a list downloaded from https://user-agents.net, the regexes in this package hit a 90% detection rate.
If nothing matches, it also checks if the user agent is present in the list.

Usage

import "github.com/stephenafamo/isbot"

func main() {
    userAgent := "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.0.0 Safari/537.36 Chrome-Lighthouse"
    isBot := isbot.Check(userAgent)
    if isBot {
        // do something
    }
}

Sources

The sources for detection are:

Contributing

Run go generate to refresh the lists from the sources.

If something is misisng, send in a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(userAgent string) bool

Check using both methods

func CheckList

func CheckList(userAgent string) bool

Check using the list of known user agent strings

func CheckRegex

func CheckRegex(userAgent string) bool

Check using only the regexes

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL