Documentation ¶
Overview ¶
Package ipdata is a client for the https://ipdata.co API. It provides functions for looking up data, as well as parsing the data in a programmatic way. The simplest usage is to build a new client and then use the Lookup method.
If you have any problems with this client, please raise an issue on GitHub:
* https://github.com/theckman/go-ipdata/issues
Example usage:
import "github.com/theckman/go-ipdata" ipd := ipdata.NewClient("") // API key is optional data, err := ipd.Lookup("8.8.8.8")
Index ¶
- Constants
- type ASN
- type Client
- func (c *Client) BulkLookup(ips []string) ([]*IP, error)
- func (c *Client) BulkLookupWithContext(ctx context.Context, ips []string) ([]*IP, error)
- func (c Client) Lookup(ip string) (IP, error)
- func (c Client) LookupWithContext(ctx context.Context, ip string) (IP, error)
- func (c *Client) RawBulkLookup(ips []string) (*http.Response, error)
- func (c *Client) RawBulkLookupWithContext(ctx context.Context, ips []string) (*http.Response, error)
- func (c Client) RawLookup(ip string) (*http.Response, error)
- func (c Client) RawLookupWithContext(ctx context.Context, ip string) (*http.Response, error)
- type Currency
- type Error
- type IP
- type Language
- type Threat
- type TimeZone
Constants ¶
const Version = "0.7.1"
Version is the package version
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ASN ¶ added in v0.6.1
type ASN struct { ASN string `json:"asn"` Name string `json:"name"` Domain string `json:"domain"` Route string `json:"route"` Type string `json:"type"` }
ASN represents the Autonomous System Number data returned from the API.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the struct to represent the functionality presented by the https://ipdata.co API.
func NewClient ¶
NewClient takes an optional API key and returns a Client. If you do not have an API key use an empty string ("").
func (*Client) BulkLookup ¶ added in v0.7.0
BulkLookup takes a set of IP addresses, and returns a set of results from the API. If the request failed, or something was wrong with one of the inputs, the error value will be of type Error. If err is non-nil, the []*IP slice may contain data (if it was able to process some of the inputs). The error value will contain the index of the first error in the bulk response.
Please note, any IPs that had a failed lookup will be a nil entry in the slice when an error is returned. So if you start to use the []*IP when err != nil, you will need to add explicit nil checks to avoid pointer derefence panics.
func (*Client) BulkLookupWithContext ¶ added in v0.7.2
BulkLookupWithContext is a BulkLookup with a provided context.Context.
func (Client) Lookup ¶
Lookup takes an IP address to look up the details for. An empty string means you want the information about the current node's pubilc IP address. If an API error occurs, the error value will be of type Error.
func (Client) LookupWithContext ¶ added in v0.7.2
LookupWithContext is a Lookup that uses a provided context.Context.
func (*Client) RawBulkLookup ¶ added in v0.7.0
RawBulkLookup takes a set of IP addresses, and returns the response from the API.
func (*Client) RawBulkLookupWithContext ¶ added in v0.7.2
func (c *Client) RawBulkLookupWithContext(ctx context.Context, ips []string) (*http.Response, error)
RawBulkLookupWithContext is a RawBulkLookup with a provided context.Context.
type Currency ¶ added in v0.5.0
type Currency struct { Name string `json:"name"` Code string `json:"code"` Symbol string `json:"symbol"` Native string `json:"native"` Plural string `json:"plural"` }
Currency represents the currency object within the JSON response from the API. This provides information about the currency where that IP resides.
type Error ¶ added in v0.6.0
type Error struct {
// contains filtered or unexported fields
}
Error represents an error returned from the ipdata.co API. This error value will be used whenever the HTTP request to the API completed, but the HTTP status code indicated failure. The Error() method will return the JSON message sent by the API, if present, and Code() returns the numeric HTTP status code.
func (Error) Code ¶ added in v0.6.0
Code returns the HTTP Status code returned from the ipdata.co API.
type IP ¶
type IP struct { IP string `json:"ip"` ASN ASN `json:"asn"` Organization string `json:"organisation"` City string `json:"city"` Region string `json:"region"` RegionCode string `json:"region_code"` Postal string `json:"postal"` CountryName string `json:"country_name"` CountryCode string `json:"country_code"` Flag string `json:"flag"` EmojiFlag string `json:"emoji_flag"` EmojiUnicode string `json:"emoji_unicode"` ContinentName string `json:"continent_name"` ContinentCode string `json:"continent_code"` Latitude float64 `json:"latitude"` Longitude float64 `json:"longitude"` CallingCode string `json:"calling_code"` IsEU bool `json:"is_eu"` Languages []Language `json:"language,omitempty"` Currency *Currency `json:"currency,omitempty"` TimeZone *TimeZone `json:"time_zone,omitempty"` Threat *Threat `json:"threat,omitempty"` }
IP is a struct that represents the JSON response from the https://ipdata.co API.
type Language ¶ added in v0.5.0
Language represents the language object within the JSON response from the API. This provides information about the language(s) where that IP resides.
type Threat ¶ added in v0.5.0
type Threat struct { // IsTOR is true if the IP is associated with a node on the TOR (The Onion // Router) network IsTOR bool `json:"is_tor"` // IsProxy is true if the IP is associated with bring a proxy // (HTTP/HTTPS/SSL/SOCKS/CONNECT and transparent proxies) IsProxy bool `json:"is_proxy"` // IsAnonymous is true if either IsTor or IsProxy are true IsAnonymous bool `json:"is_anonymous"` // IsKnownAttacker is true if the IP address is a known source of malicious // activity (i.e. attacks, malware, botnet activity, etc) IsKnownAttacker bool `json:"is_known_attacker"` // IsKnownAbuser is true if the IP address is a known source of abuse // (i.e. spam, harvesters, registration bots, and other nuisance bots, etc) IsKnownAbuser bool `json:"is_known_abuser"` // IsThreat is true if either IsKnownAttacker or IsKnownAbuser are true IsThreat bool `json:"is_threat"` // IsBogon is true if this IP address should be within a bogon filter: // https://en.wikipedia.org/wiki/Bogon_filtering IsBogon bool `json:"is_bogon"` }
Threat represents the threat object within the JSON response from the API. This provides information about what type of threat this IP may be.
type TimeZone ¶ added in v0.5.0
type TimeZone struct { Name string `json:"name"` Abbreviation string `json:"abbr"` Offset string `json:"offset"` IsDST bool `json:"is_dst"` CurrentTime string `json:"current_time,omitempty"` }
TimeZone represents the time_zone object within the JSON response from the API. This provides information about the timezone where that IP resides.