An unofficial GoLang wrapper around IPInfo.
- IP Lookup
- ASN Lookup
go get github.com/aaomidi/go-ipinfo/...
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")
}
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.
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 |
Code is the best documentation for this.
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")