https://github.com/whois-api-llc/go-simple-geoip
The simplest possible way to get IP geolocation information in Go.
https://github.com/whois-api-llc/go-simple-geoip
geolocation geolocation-api go golang ip-geolocation whoisxmlapi
Last synced: about 1 year ago
JSON representation
The simplest possible way to get IP geolocation information in Go.
- Host: GitHub
- URL: https://github.com/whois-api-llc/go-simple-geoip
- Owner: whois-api-llc
- License: mit
- Created: 2022-05-18T13:01:19.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-18T13:08:30.000Z (about 4 years ago)
- Last Synced: 2025-01-25T21:27:59.056Z (over 1 year ago)
- Topics: geolocation, geolocation-api, go, golang, ip-geolocation, whoisxmlapi
- Language: Go
- Homepage: https://ip-geolocation.whoisxmlapi.com/api
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/licenses/MIT)
[](https://pkg.go.dev/github.com/whois-api-llc/go-simple-geoip)
[](https://github.com/whois-api-llc/go-simple-geoip/actions/)
# Overview
The client library for
[IP Geolocation API](https://ip-geolocation.whoisxmlapi.com)
in Go language.
The minimum go version is 1.17.
# Installation
The library is distributed as a Go module
```bash
go get github.com/whois-api-llc/go-simple-geoip
```
# Examples
Full API documentation available [here](https://ip-geolocation.whoisxmlapi.com/api/documentation/making-requests)
You can find all examples in `example` directory.
## Create a new client
To start making requests you need the API Key.
You can find it on your profile page on [whoisxmlapi.com](https://whoisxmlapi.com/).
Using the API Key you can create Client.
Most users will be fine with `NewBasicClient` function.
```go
client := simplegeoip.NewBasicClient(apiKey)
```
If you want to set custom `http.Client` to use proxy then you can use `NewClient` function.
```go
transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
client := simplegeoip.NewClient(apiKey, simplegeoip.ClientParams{
HTTPClient: &http.Client{
Transport: transport,
Timeout: 20 * time.Second,
},
})
```
## Make basic requests
IP Geolocation API lets you check geographical location by IP address, domain name or email address.
```go
// Make request to get parsed IP Geolocation API response for the client's public IP address
geoipResp, resp, err := client.GeoipService.Get(ctx)
if err != nil {
log.Fatal(err)
}
log.Println(geoipResp.IP)
log.Println(geoipResp.Location.Country)
// Make request to get raw IP Geolocation API data
resp, err := client.GeoipService.GetRaw(ctx)
if err != nil {
log.Fatal(err)
}
log.Println(string(resp.Body))
```