mondern slopify hand crafted code for the greater good.
(move from user specified blocklist download URLs to simply country codes with multiple providers available.)
This commit is contained in:
27
provider.go
Normal file
27
provider.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user