Giter VIP home page Giter VIP logo

go's Introduction

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

go's People

Contributors

jaunt avatar jonathan-kosgei avatar obitech avatar theckman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.