Coder Social home page Coder Social logo

go-ipinfo's Introduction

GO IPInfo

License Travis Go Report Card GoDoc

An unofficial GoLang wrapper around IPInfo.

Features:

  • IP Lookup
  • ASN Lookup

Installing it

go get github.com/aaomidi/go-ipinfo/...

Using it

Examples

To get information about an IP:

func main() {

    api := IPInfo{Token: "YOUR_TOKEN"}

    ip := net.ParseIP("8.8.8.8")

    response, err := api.LookupIP(ip) // Type IPResponse
}

To get the information about an ASN:

func main() {
    api := IPInfo{Token: "YOUR_TOKEN"}

    response, err := api.LookupASN("AS7922")
}

Errors

We've provided several errors to help you check for common issues:

  • RateLimitedError - This error is telling you that you've been limited by the wrapper.
  • ErrorResponseError - This error is telling you that the response from one of the API endpoints was an error.
  • NoSuchCountryError - This error is telling you that the ISO2 country code couldn't be translated to a country name.

IPInfo Structure

The struct IPInfo is the entry point to this library. None of the values in the struct are required, and will be set to defaults if you do not set them.

Consult the table to see what the default value of these variables are:

Variable Purpose Default Value
Token Token used to communicate with the API Empty string ""
Client A pointer to the http.Client. The default http.Client with a timeout of 5 seconds
LanguageReader A pointer to io.Reader. This reader will be used to decode the json language file. A reader to static/en_US.json

The other structs

Code is the best documentation for this.

The language system

We've included an example English, United States language file. You can include your own and provide the reader to us using: os.Open("path/to/file")

go-ipinfo's People

Contributors

aaomidi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

przmv

go-ipinfo's Issues

open ../static/en_US.json: no such file or directory

When I try to use go-ipinfo package I get the following error:

open ../static/en_US.json: no such file or directory

Probably it makes sense to provide countries data as a Go map structure using go generate.

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.