https://github.com/ipdata/go
Official Golang client library for the ipdata API
https://github.com/ipdata/go
geolocation geolocation-api go ipdata
Last synced: about 12 hours ago
JSON representation
Official Golang client library for the ipdata API
- Host: GitHub
- URL: https://github.com/ipdata/go
- Owner: ipdata
- License: mit
- Created: 2017-12-11T03:34:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-09T15:58:44.000Z (over 1 year ago)
- Last Synced: 2025-10-25T23:33:47.156Z (3 months ago)
- Topics: geolocation, geolocation-api, go, ipdata
- Language: Go
- Homepage: https://ipdata.co
- Size: 182 KB
- Stars: 20
- Watchers: 2
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ipdata
[](https://github.com/theckman/go-ipdata/blob/master/LICENSE)
[](https://godoc.org/github.com/theckman/go-ipdata)
[](https://github.com/theckman/go-ipdata/releases)
[](https://travis-ci.org/theckman/go-ipdata/branches)
[](https://gocover.io/github.com/theckman/go-ipdata)
[](https://goreportcard.com/report/github.com/theckman/go-ipdata)
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](https://github.com/theckman/go-ipdata/blob/master/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:
```Go
import (
"github.com/ipdata/go"
"fmt"
)
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:
```Go
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](https://github.com/theckman/) - Created the first version of this library