(move from user specified blocklist download URLs to simply country codes with multiple providers available.)
28 lines
791 B
Go
28 lines
791 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
// Provider defines the interface for GeoIP data sources.
|
|
// Each provider knows how to fetch IPv4 CIDR blocks for a given country.
|
|
type Provider interface {
|
|
// Name returns the human-readable name of this provider.
|
|
Name() string
|
|
|
|
// FetchCIDRs downloads and returns a slice of IPv4 CIDR strings
|
|
// for the given ISO 3166-1 alpha-2 country code (lowercase).
|
|
FetchCIDRs(countryCode string) ([]string, error)
|
|
}
|
|
|
|
// NewProvider creates a Provider by name.
|
|
// Supported providers: "ipverse", "ipdeny"
|
|
func NewProvider(name string) (Provider, error) {
|
|
switch name {
|
|
case "ipverse":
|
|
return &IPverseProvider{}, nil
|
|
case "ipdeny":
|
|
return &IPDenyProvider{}, nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown provider %q (supported: ipverse, ipdeny)", name)
|
|
}
|
|
}
|