Categorygithub.com/gooblitz/go-ipdata
modulepackage
0.7.2
Repository: https://github.com/gooblitz/go-ipdata.git
Documentation: pkg.go.dev

# README

ipdata

License GoDoc Latest Git Tag Travis master Build Status Go Cover Test Coverage Go Report Card

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.

License

This code is released under the MIT License. Please see the LICENSE for the full content of the license.

Contributing

If you'd like to contribute to this project, I welcome any pull requests against this repo. The only ask is that a GitHub issue be opened detailing the desired functionality before making any pull requests.

Usage

The service provided by ipdata requires an API key before making API calls. Attempts to create a client without one will fail, as would attempts to contact the API. You can get an API key from https://ipdata.co/.

Here is a simple example of using the library:

import "github.com/theckman/go-ipdata"

ipd := ipdata.NewClient("EXAMPLE_API_KEY")

data, err := ipd.Lookup("8.8.8.8")
if err != nil {
	// handle error
}

fmt.Printf("%s (%s)\n", data.IP, data.ASN)

Errors returned from the lookup function calls may be of type Error, which includes the message from the API and the HTTP status code. The Error() method on this type only returns the message and not the status code. To maintain compatibility with Go 1.12.x, this is still using github.com/pkg/errors for error management:

import "github.com/pkg/errors"

data, err := ipd.Lookup("8.8.8.8")
if err != nil {
	// do a type assertion on the error
	rerr, ok := errors.Cause(err).(ipdata.Error)

    if !ok {
    	// this wasn't a failure from rate limiting
    }
    
    fmt.Println("%d: %s", rerr.Code(), rerr.Error())
}

Contributors

  • Tim Heckman - Created the first version of this library

# Functions

NewClient takes an optional API key and returns a Client.

# Constants

Version is the package version.

# Structs

ASN represents the Autonomous System Number data returned from the API.
Client is the struct to represent the functionality presented by the https://ipdata.co API.
Currency represents the currency object within the JSON response from the API.
Error represents an error returned from the ipdata.co API.
IP is a struct that represents the JSON response from the https://ipdata.co API.
Language represents the language object within the JSON response from the API.
Threat represents the threat object within the JSON response from the API.
TimeZone represents the time_zone object within the JSON response from the API.