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 +} +