Skip to content

Commit

Permalink
Merge pull request #22 from BenB196/update-readme
Browse files Browse the repository at this point in the history
refactor: update readme
  • Loading branch information
BenB196 authored Oct 12, 2024
2 parents 15c4587 + 03fcc51 commit 67e8835
Showing 1 changed file with 63 additions and 40 deletions.
103 changes: 63 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

A third party Golang package for integrating Golang projects with [IP-API's](http://ip-api.com/) API.

The goal of this Golang package is to provide an easy to use package for integrating IP-API's API into the Golang environment.
The goal of this Golang package is to provide an easy-to-use package for integrating IP-API's API into the Golang
environment.

## Structs

Expand All @@ -29,40 +30,43 @@ type QueryIP struct {
}
```

List of possible fields that can be passed: status, message, continent, continentCode, country, countryCode, region, regionName, city, district, zip, lat, lon, timezone, isp, org, as, asname, reverse, mobile, proxy, query [1](http://ip-api.com/docs/api:json)
List of possible fields that can be passed: status, message, continent, continentCode, country, countryCode, region,
regionName, city, district, zip, lat, lon, timezone, offset, isp, org, as, asname, reverse, mobile, proxy,
query [1](http://ip-api.com/docs/api:json)

List of possible languages that can be passed: en, de, es, pt-BR, fr, ja, zh-CN, ru [2](http://ip-api.com/docs/api:json)

### Location struct

The location struct is designed to take the return of the IP-API query and provide it in an easy to use struct.
The location struct is designed to take the return of the IP-API query and provide it in an easy-to-use struct.

```
```go
type Location struct {
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
Continent string `json:"continent,omitempty"`
ContinentCode string `json:"continentCode,omitempty"`
Country string `json:"country,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
Region string `json:"region,omitempty"`
RegionName string `json:"regionName,omitempty"`
City string `json:"city,omitempty"`
District string `json:"district,omitempty"`
ZIP string `json:"zip,omitempty"`
Lat *float32 `json:"lat,omitempty"`
Lon *float32 `json:"lon,omitempty"`
Timezone string `json:"timezone,omitempty"`
Currency string `json:"currency,omitempty"`
ISP string `json:"isp,omitempty"`
Org string `json:"org,omitempty"`
AS string `json:"as,omitempty"`
ASName string `json:"asame,omitempty"`
Reverse string `json:"reverse,omitempty"`
Mobile bool `json:"mobile,omitempty"`
Proxy bool `json:"proxy,omitempty"`
Hosting bool `json:"hosting,omitempty"`
Query string `json:"query,omitempty"`
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
Continent string `json:"continent,omitempty"`
ContinentCode string `json:"continentCode,omitempty"`
Country string `json:"country,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
Region string `json:"region,omitempty"`
RegionName string `json:"regionName,omitempty"`
City string `json:"city,omitempty"`
District string `json:"district,omitempty"`
ZIP string `json:"zip,omitempty"`
Lat *float32 `json:"lat,omitempty"`
Lon *float32 `json:"lon,omitempty"`
Timezone string `json:"timezone,omitempty"`
Offset *int `json:"offset,omitempty"`
Currency string `json:"currency,omitempty"`
ISP string `json:"isp,omitempty"`
Org string `json:"org,omitempty"`
AS string `json:"as,omitempty"`
ASName string `json:"asname,omitempty"`
Reverse string `json:"reverse,omitempty"`
Mobile *bool `json:"mobile,omitempty"`
Proxy *bool `json:"proxy,omitempty"`
Hosting *bool `json:"hosting,omitempty"`
Query string `json:"query,omitempty"`
}
```

Expand All @@ -75,58 +79,77 @@ There are four (4) main functions within this package:
3. ValidateFields
4. ValidateLang

These functions allow someone to query IP-API's API within Golang and return the values as Golang structs to be used within other Golang applications.
These functions allow someone to query IP-API's API within Golang and return the values as Golang structs to be used
within other Golang applications.

### SingleQuery function

The SingleQuery function is designed to make a single request against the API.

Arguments:
- query - This is a Golang struct which when passed to the function will be reformatted into a proper query to be executed against the IP-API API.
- apiKey - This is for when you are using the pro version of IP-API and which to have the [increased functionality](https://members.ip-api.com/).
- baseURL - This is really only intended to be used if you are going through some sort of IP-API proxy. Otherwise, this can be left blank, and the URL will be determined by whether an API Key is provided or not.

- query - This is a Golang struct which when passed to the function will be reformatted into a proper query to be
executed against the IP-API API.
- apiKey - This is for when you are using the pro version of IP-API and which to have
the [increased functionality](https://members.ip-api.com/).
- baseURL - This is really only intended to be used if you are going through some sort of IP-API proxy. Otherwise, this
can be left blank, and the URL will be determined by whether an API Key is provided or not.

Returns:

- Location - Golang struct that contains the results of the query.
- error - Any errors.

### BatchQuery function

The BatchQuery function is designed to take advantage of IP-API's [batch](http://ip-api.com/docs/api:batch) API. This is designed to allow for multiple queries to be executed at the same time to reduce overall query time.
The BatchQuery function is designed to take advantage of IP-API's [batch](http://ip-api.com/docs/api:batch) API. This is
designed to allow for multiple queries to be executed at the same time to reduce overall query time.

Arguments:
- query - This is a Golang struct which when passed to the function will be reformatted into a proper query to be executed against the IP-API API.
- apiKey - This is for when you are using the pro version of IP-API and which to have the [increased functionality](https://members.ip-api.com/).
- baseURL - This is really only intended to be used if you are going through some sort of IP-API proxy. Otherwise, this can be left blank, and the URL will be determined by whether an API Key is provided or not.

- query - This is a Golang struct which when passed to the function will be reformatted into a proper query to be
executed against the IP-API API.
- apiKey - This is for when you are using the pro version of IP-API and which to have
the [increased functionality](https://members.ip-api.com/).
- baseURL - This is really only intended to be used if you are going through some sort of IP-API proxy. Otherwise, this
can be left blank, and the URL will be determined by whether an API Key is provided or not.

Returns:

- []Location - Golang slice of location structs that contains the results of the query.
- error - Any errors.

An observation about the batch query. It sometime appears to return less data then the single query on the exact same query even when the same fields are passed. This is something that appears to be on the IP-API end, not the package end.
An observation about the batch query. It sometime appears to return less data then the single query on the exact same
query even when the same fields are passed. This is something that appears to be on the IP-API end, not the package end.

### ValidateFields function

The ValidateFields function is designed to validate that the fields which are being passed to the IP-API are valid.

Arguments:
- fields - This is a string which contains comma separated values of the fields. It will be checked against the AllowedAPIFields.

- fields - This is a string which contains comma separated values of the fields. It will be checked against the
AllowedAPIFields.

Returns:
- string - The same string which was passed to it in the fields argument.

- string - The same string which was passed to it in the fields' argument.
- error - Any errors.

### ValidateLang function

The validateLang function is designed to validate the lang string which is one of the languages supported by IP-API.

Arguments:

- lang - the string which contains the desired language.

Returns:

- string - The same string which was passed to it in the lang argument.
- error - Any errors.

#Important

I currently have not tested the functionality of the Pro-stuff as I don't currently have access to it. If you encounter any issues with it, please let me know so that I can fix them.
I currently have not tested the functionality of the Pro-stuff as I don't currently have access to it. If you encounter
any issues with it, please let me know so that I can fix them.

0 comments on commit 67e8835

Please sign in to comment.