Skip to content
/ go Public
forked from ipdata/go

Official Golang client library for the ipdata API

License

Notifications You must be signed in to change notification settings

tnuanchuay/go

Repository files navigation

go-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 can be used anonymously or with an API key. The anonymous usage is subject to rate limits. If you are using the anonymous service, providing an empty string as an API key is how you inform the API client to issue anonymous requests.

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

ipd := ipdata.NewClient("")

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

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

You can also use the error returned from the methods to determine whether it was a failure due to a rate limit. This package uses the github.com/pkg/errors package for error handling, which allows you to wrap errors to provide more context. Using this functionality is entirely optional.

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).(interface{
    	RateLimited() bool
    })

    if !ok {
    	// this wasn't a failure from rate limiting
    }

    if rerr.RateLimited() {
    	// we were rate limited
    }
}

About

Official Golang client library for the ipdata API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.5%
  • Makefile 1.5%