Documentation
¶
Index ¶
- Variables
- func FetchMultiInfo(ctx context.Context, fetcher InfoFetcher, ips []netip.Addr) (results []models.PublicIP, err error)
- type Fetcher
- type InfoFetcher
- type NameToken
- type Provider
- type ResilientFetcher
- func (r *ResilientFetcher) CanFetchAnyIP() bool
- func (r *ResilientFetcher) FetchInfo(ctx context.Context, ip netip.Addr) (result models.PublicIP, err error)
- func (r *ResilientFetcher) String() string
- func (r *ResilientFetcher) Token() string
- func (r *ResilientFetcher) UpdateFetchers(fetchers []Fetcher)
- type Warner
Constants ¶
This section is empty.
Variables ¶
var ( ErrTokenNotValid = errors.New("token is not valid") ErrTooManyRequests = errors.New("too many requests sent for this month") ErrBadHTTPStatus = errors.New("bad HTTP status received") ErrServiceLimited = errors.New("service is limited") )
var ErrCustomURLNotValid = errors.New("custom URL is not valid")
var ErrFetchersAllRateLimited = errors.New("all fetchers are rate limited")
var ErrProviderNotValid = errors.New("API name is not valid")
Functions ¶
func FetchMultiInfo ¶
func FetchMultiInfo(ctx context.Context, fetcher InfoFetcher, ips []netip.Addr) ( results []models.PublicIP, err error, )
FetchMultiInfo obtains the public IP address information for every IP addresses provided and returns a slice of results with the corresponding order as to the IP addresses slice order. If an error is encountered, all the operations are canceled and an error is returned, so the results returned should be considered incomplete in this case.
Types ¶
type Fetcher ¶
type Fetcher interface { String() string CanFetchAnyIP() bool Token() (token string) InfoFetcher }
type InfoFetcher ¶
type ResilientFetcher ¶
type ResilientFetcher struct {
// contains filtered or unexported fields
}
func NewResilient ¶
func NewResilient(fetchers []Fetcher, logger Warner) *ResilientFetcher
NewResilient creates a 'resilient' fetcher given multiple fetchers. For example, it can handle bans and move on to another fetcher if one fails.
func (*ResilientFetcher) CanFetchAnyIP ¶
func (r *ResilientFetcher) CanFetchAnyIP() bool
CanFetchAnyIP returns true if any of the fetchers can fetch any IP address and is not banned.
func (*ResilientFetcher) FetchInfo ¶
func (r *ResilientFetcher) FetchInfo(ctx context.Context, ip netip.Addr) ( result models.PublicIP, err error, )
FetchInfo obtains information on the ip address provided. If the ip is the zero value, the public IP address of the machine is used as the IP. If a fetcher gets banned, the next one is tried – until all have been exhausted. Fetchers still within their banned period are skipped. If an error unrelated to being banned is encountered, it is returned and more fetchers are tried.
func (*ResilientFetcher) String ¶
func (r *ResilientFetcher) String() string
func (*ResilientFetcher) Token ¶
func (r *ResilientFetcher) Token() string
func (*ResilientFetcher) UpdateFetchers ¶
func (r *ResilientFetcher) UpdateFetchers(fetchers []Fetcher)