geo

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	AWSGeoUrl  = "https://ip-ranges.amazonaws.com/ip-ranges.json"
	AWSExpired = 7 * 24 * time.Hour
	AWSFile    = "aws-ip.json"
)
View Source
const (
	GCPGeoUrl  = "https://www.gstatic.com/ipranges/cloud.json"
	GCPExpired = 7 * 24 * time.Hour
	GCPFile    = "gcp-ip.json"
)
View Source
const (
	Geolite2Url    = "https://githubusercontent.nknorg.workers.dev/leo108/geolite2-db/master/Country.mmdb"
	MaxMindExpired = 30 * 24 * time.Hour
	MaxMindFile    = "geolite2-country.mmdb"
)
View Source
const (
	GeoIPRetry = 3
	IP2CUrl    = "http://ip2c.org/"
)

Variables

View Source
var AWSRegionMapping = map[string]string{
	"us-east-1":      "US",
	"us-east-2":      "US",
	"us-west-1":      "US",
	"us-west-2":      "US",
	"af-south-1":     "ZA",
	"ap-east-1":      "HK",
	"ap-south-1":     "IN",
	"ap-northeast-1": "JP",
	"ap-northeast-2": "KR",
	"ap-northeast-3": "JP",
	"ap-southeast-1": "SG",
	"ap-southeast-2": "AU",
	"ca-central-1":   "CA",
	"eu-central-1":   "DE",
	"eu-west-1":      "IE",
	"eu-west-2":      "GB",
	"eu-west-3":      "FR",
	"eu-south-1":     "IT",
	"eu-north-1":     "SE",
	"me-south-1":     "BH",
	"sa-east-1":      "BR",
}
View Source
var GCPScopeMapping = map[string]string{
	"asia-east1":              "TW",
	"asia-east2":              "HK",
	"asia-northeast1":         "JP",
	"asia-northeast2":         "JP",
	"asia-northeast3":         "KR",
	"asia-south1":             "IN",
	"asia-southeast1":         "SG",
	"asia-southeast2":         "ID",
	"australia-southeast1":    "AU",
	"europe-north1":           "FI",
	"europe-west1":            "BE",
	"europe-west2":            "GB",
	"europe-west3":            "DE",
	"europe-west4":            "NL",
	"europe-west6":            "CH",
	"northamerica-northeast1": "CA",
	"southamerica-east1":      "BR",
	"us-central1":             "US",
	"us-east1":                "US",
	"us-east4":                "US",
	"us-west1":                "US",
	"us-west2":                "US",
	"us-west3":                "US",
	"us-west4":                "US",
}

Functions

This section is empty.

Types

type AWSGeoInfo

type AWSGeoInfo struct {
	SyncToken  string      `json:"syncToken"`
	CreateDate string      `json:"createDate"`
	Prefixes   []AWSIPInfo `json:"prefixes"`
}

type AWSIPInfo

type AWSIPInfo struct {
	IPPrefix           string     `json:"ip_prefix"`
	Region             string     `json:"region"`
	Service            string     `json:"service"`
	NetworkBorderGroup string     `json:"network_border_group"`
	Subnet             *net.IPNet `json:"-"`
}

type AWSProvider

type AWSProvider struct {
	Info *AWSGeoInfo
	// contains filtered or unexported fields
}

func NewAWSProvider

func NewAWSProvider(path string) *AWSProvider

func (*AWSProvider) DownloadUrl

func (p *AWSProvider) DownloadUrl() string

func (*AWSProvider) FileName

func (p *AWSProvider) FileName() string

func (*AWSProvider) GetLocation

func (p *AWSProvider) GetLocation(ip string) (*Location, error)

func (*AWSProvider) LastUpdate

func (p *AWSProvider) LastUpdate() time.Time

func (*AWSProvider) MaybeUpdate

func (p *AWSProvider) MaybeUpdate() error

func (*AWSProvider) MaybeUpdateContext

func (p *AWSProvider) MaybeUpdateContext(ctx context.Context) error

func (*AWSProvider) NeedUpdate

func (p *AWSProvider) NeedUpdate() bool

func (*AWSProvider) Ready

func (p *AWSProvider) Ready() bool

func (*AWSProvider) SetFileName

func (p *AWSProvider) SetFileName(name string)

func (*AWSProvider) SetReady

func (p *AWSProvider) SetReady(ready bool)

type GCPGeoInfo

type GCPGeoInfo struct {
	SyncToken    string      `json:"syncToken"`
	CreationTime string      `json:"creationTime"`
	Prefixes     []GCPIPInfo `json:"prefixes"`
}

type GCPIPInfo

type GCPIPInfo struct {
	Ipv4Prefix string     `json:"ipv4Prefix"`
	Service    string     `json:"service"`
	Scope      string     `json:"scope"`
	Subnet     *net.IPNet `json:"-"`
}

type GCPProvider

type GCPProvider struct {
	Info *GCPGeoInfo
	// contains filtered or unexported fields
}

func NewGCPProvider

func NewGCPProvider(path string) *GCPProvider

func (*GCPProvider) DownloadUrl

func (p *GCPProvider) DownloadUrl() string

func (*GCPProvider) FileName

func (p *GCPProvider) FileName() string

func (*GCPProvider) GetLocation

func (p *GCPProvider) GetLocation(ip string) (*Location, error)

func (*GCPProvider) LastUpdate

func (p *GCPProvider) LastUpdate() time.Time

func (*GCPProvider) MaybeUpdate

func (p *GCPProvider) MaybeUpdate() error

func (*GCPProvider) MaybeUpdateContext

func (p *GCPProvider) MaybeUpdateContext(ctx context.Context) error

func (*GCPProvider) NeedUpdate

func (p *GCPProvider) NeedUpdate() bool

func (*GCPProvider) Ready

func (p *GCPProvider) Ready() bool

func (*GCPProvider) SetFileName

func (p *GCPProvider) SetFileName(name string)

func (*GCPProvider) SetReady

func (p *GCPProvider) SetReady(ready bool)

type GeoProvider

type GeoProvider interface {
	GetLocation(ip string) (*Location, error)
	FileName() string
	DownloadUrl() string
	LastUpdate() time.Time
	NeedUpdate() bool
	MaybeUpdate() error
	MaybeUpdateContext(ctx context.Context) error
	Ready() bool
	SetReady(bool)
	SetFileName(string)
}

type IP2CProvider

type IP2CProvider struct {
}

func NewIP2CProvider

func NewIP2CProvider() *IP2CProvider

func (*IP2CProvider) DownloadUrl

func (p *IP2CProvider) DownloadUrl() string

func (*IP2CProvider) FileName

func (p *IP2CProvider) FileName() string

func (*IP2CProvider) GetLocation

func (p *IP2CProvider) GetLocation(ip string) (*Location, error)

func (*IP2CProvider) LastUpdate

func (p *IP2CProvider) LastUpdate() time.Time

func (*IP2CProvider) MaybeUpdate

func (p *IP2CProvider) MaybeUpdate() error

func (*IP2CProvider) MaybeUpdateContext

func (p *IP2CProvider) MaybeUpdateContext(ctx context.Context) error

func (*IP2CProvider) NeedUpdate

func (p *IP2CProvider) NeedUpdate() bool

func (*IP2CProvider) Ready

func (p *IP2CProvider) Ready() bool

func (*IP2CProvider) SetFileName

func (p *IP2CProvider) SetFileName(string)

func (*IP2CProvider) SetReady

func (p *IP2CProvider) SetReady(bool)

type IPFilter

type IPFilter struct {
	Allow    []Location `json:"allow"`
	Disallow []Location `json:"disallow"`
	// contains filtered or unexported fields
}

func (*IPFilter) AddProvider

func (f *IPFilter) AddProvider(download bool, path string)

func (*IPFilter) AllowIP

func (f *IPFilter) AllowIP(ip string) (bool, error)

func (*IPFilter) AllowLocation

func (f *IPFilter) AllowLocation(loc *Location) bool

func (*IPFilter) Empty

func (f *IPFilter) Empty() bool

func (*IPFilter) GetLocation

func (f *IPFilter) GetLocation(ip string) *Location

func (*IPFilter) GetProviders

func (f *IPFilter) GetProviders() []GeoProvider

func (*IPFilter) NeedGeoInfo

func (f *IPFilter) NeedGeoInfo() bool

func (*IPFilter) StartUpdateDataFile

func (f *IPFilter) StartUpdateDataFile(c chan struct{})

func (*IPFilter) UpdateDataFile

func (f *IPFilter) UpdateDataFile()

func (*IPFilter) UpdateDataFileContext

func (f *IPFilter) UpdateDataFileContext(ctx context.Context)

type Location

type Location struct {
	IP          string `json:"ip"`
	CountryCode string `json:"countryCode"`
	Country     string `json:"country"`
	City        string `json:"city"`
	// contains filtered or unexported fields
}

func (*Location) Empty

func (l *Location) Empty() bool

func (*Location) Match

func (l *Location) Match(location *Location) bool

type MaxMindProvider

type MaxMindProvider struct {
	DB *geoip2.Reader
	// contains filtered or unexported fields
}

func NewMaxMindProvider

func NewMaxMindProvider(path string) *MaxMindProvider

func (*MaxMindProvider) DownloadUrl

func (p *MaxMindProvider) DownloadUrl() string

func (*MaxMindProvider) FileName

func (p *MaxMindProvider) FileName() string

func (*MaxMindProvider) GetLocation

func (p *MaxMindProvider) GetLocation(ip string) (*Location, error)

func (*MaxMindProvider) LastUpdate

func (p *MaxMindProvider) LastUpdate() time.Time

func (*MaxMindProvider) MaybeUpdate

func (p *MaxMindProvider) MaybeUpdate() error

func (*MaxMindProvider) MaybeUpdateContext

func (p *MaxMindProvider) MaybeUpdateContext(ctx context.Context) error

func (*MaxMindProvider) NeedUpdate

func (p *MaxMindProvider) NeedUpdate() bool

func (*MaxMindProvider) Ready

func (p *MaxMindProvider) Ready() bool

func (*MaxMindProvider) SetFileName

func (p *MaxMindProvider) SetFileName(name string)

func (*MaxMindProvider) SetReady

func (p *MaxMindProvider) SetReady(ready bool)

Jump to

Keyboard shortcuts

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