blocklist

package
v0.0.0-...-f8b8a36 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package blocklist provides a blocklist based on ip and user-agent regexp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blocklist

type Blocklist struct {
	Code    *int    `yaml:"code"`
	Message *string `yaml:"message"`

	IP []string `yaml:"ip"`
	UA []string `yaml:"ua"`
	// contains filtered or unexported fields
}

A Blocklist is a IP and User-Agent based blocklist.

Zero value is a valid Blocklist that matches nothing.

A non-zero Blocklist must call Parse first before it can be used.

func ParseYAML

func ParseYAML(ctx context.Context, r io.Reader) (Blocklist, error)

ParseYAML creates a Blocklist from yaml config.

It also uses strict parsing mode.

func (Blocklist) Check

func (b Blocklist) Check(r *http.Request) error

Check returns an error if the request matches the blocklist.

func (Blocklist) Middleware

func (b Blocklist) Middleware(next http.Handler) http.Handler

Middleware provides a HTTP middleware based on the configured blocklist.

func (*Blocklist) Parse

func (b *Blocklist) Parse(ctx context.Context)

Parse parses raw IP and UA strings.

It logs all unparsable IP or UA lines as warning level logs.

Jump to

Keyboard shortcuts

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