From 060bdff85f73f2a262c4d043b0e4cf735384460c Mon Sep 17 00:00:00 2001 From: hoelee Date: Tue, 12 May 2026 10:48:00 +0800 Subject: [PATCH] feat(botfilter): add New --- botfilter.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/botfilter.go b/botfilter.go index 70a9da88..cad192cc 100644 --- a/botfilter.go +++ b/botfilter.go @@ -21,3 +21,21 @@ type botFilter struct { logger filterLogger } +// New constructs a Traefik middleware. Its signature is the interface used +// by Traefik's Go plugin runtime. +func New(_ context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { + if next == nil { + return nil, fmt.Errorf("botfilter: next handler is nil") + } + compiled, err := compileConfig(config) + if err != nil { + return nil, err + } + return &botFilter{ + next: next, + config: compiled, + cache: newClientCache(compiled), + logger: filterLogger{name: name, enabled: compiled.LogBlockedRequests}, + }, nil +} +