ipcountryblocker

package
v0.0.0-...-a1dc72b Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	// IsBlockedCountry checks if a country is in the blocked list.
	// isoCode must be an ISO 3166-1 alpha-2 country code.
	IsBlockedCountry(isoCode string) bool

	// IsBlockedIP determines if an IP address originates from a blocked country.
	// Returns false for nil IP addresses or if country lookup fails.
	IsBlockedIP(ctx context.Context, ip net.IP) bool

	// GetCountryCode returns the ISO 3166-1 alpha-2 country code for an IP address.
	// Returns an error if the lookup fails or no country is found.
	GetCountryCode(ctx context.Context, ip net.IP) (string, error)

	// Close releases resources associated with the provider.
	Close() error
}

Provider defines the interface for IP-based country blocking operations. It provides methods to check if an IP or country is blocked and to retrieve country codes for given IP addresses.

func NewProvider

func NewProvider(cfg *config.Configuration, logger *slog.Logger) Provider

NewProvider creates a new IP country blocking provider using the provided configuration. It initializes the GeoIP2 database and sets up the blocked countries list. Fatally crashes the entire application if the database cannot be opened.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳