diff options
| author | Xe Iaso <me@xeiaso.net> | 2025-04-22 07:49:41 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-22 07:49:41 -0400 |
| commit | 84b28760b3b54c7d26ad40a1e7343d6de242ad9b (patch) | |
| tree | 3104e239da1ac3cedc43ee07d58bb6ad5cc9f12c /cmd/anubis | |
| parent | 9b7bf8ee06fd84f3aa3298f483d8bca69c3372d4 (diff) | |
| download | anubis-84b28760b3b54c7d26ad40a1e7343d6de242ad9b.tar.xz anubis-84b28760b3b54c7d26ad40a1e7343d6de242ad9b.zip | |
feat(lib): use Checker type instead of ad-hoc logic (#318)
This makes each check into its own type that has encapsulated check
logic, meaning that it's easier to add new checker implementations in
the future.
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/anubis')
| -rw-r--r-- | cmd/anubis/main.go | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go index 724f88a..222e21f 100644 --- a/cmd/anubis/main.go +++ b/cmd/anubis/main.go @@ -20,7 +20,6 @@ import ( "os" "os/signal" "path/filepath" - "regexp" "strconv" "strings" "sync" @@ -58,7 +57,7 @@ var ( ogPassthrough = flag.Bool("og-passthrough", false, "enable Open Graph tag passthrough") ogTimeToLive = flag.Duration("og-expiry-time", 24*time.Hour, "Open Graph tag cache expiration time") extractResources = flag.String("extract-resources", "", "if set, extract the static resources to the specified folder") - webmasterEmail = flag.String("webmaster-email", "", "if set, displays webmaster's email on the reject page for appeals") + webmasterEmail = flag.String("webmaster-email", "", "if set, displays webmaster's email on the reject page for appeals") ) func keyFromHex(value string) (ed25519.PrivateKey, error) { @@ -205,22 +204,17 @@ func main() { continue } - hash, err := rule.Hash() - if err != nil { - log.Fatalf("can't calculate checksum of rule %s: %v", rule.Name, err) - } - + hash := rule.Hash() fmt.Printf("* %s: %s\n", rule.Name, hash) } fmt.Println() // replace the bot policy rules with a single rule that always benchmarks if *debugBenchmarkJS { - userAgent := regexp.MustCompile(".") policy.Bots = []botPolicy.Bot{{ - Name: "", - UserAgent: userAgent, - Action: config.RuleBenchmark, + Name: "", + Rules: botPolicy.NewHeaderExistsChecker("User-Agent"), + Action: config.RuleBenchmark, }} } @@ -261,7 +255,7 @@ func main() { OGPassthrough: *ogPassthrough, OGTimeToLive: *ogTimeToLive, Target: *target, - WebmasterEmail: *webmasterEmail, + WebmasterEmail: *webmasterEmail, }) if err != nil { log.Fatalf("can't construct libanubis.Server: %v", err) |
