api

package
v0.0.0-...-7b4befc Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	ErrProviderNotValid = errors.New("API name is not valid")
)

Functions

func FetchMultiInfo

func FetchMultiInfo(ctx context.Context, fetcher Fetcher, 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 API

type API interface {
	FetchInfo(ctx context.Context, ip netip.Addr) (
		result models.PublicIP, err error)
}

func New

func New(provider Provider, client *http.Client, token string) (
	a API, err error)

type Fetcher

type Fetcher interface {
	FetchInfo(ctx context.Context, ip netip.Addr) (
		result models.PublicIP, err error)
}

type Provider

type Provider string
const (
	IPInfo      Provider = "ipinfo"
	IP2Location Provider = "ip2location"
)

func ParseProvider

func ParseProvider(s string) (provider Provider, err error)

Jump to

Keyboard shortcuts

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