-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48be192
commit 19e5376
Showing
1 changed file
with
19 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
# Geoip module | ||
# Geoip Module | ||
|
||
This module is used to get information about the geographical location of an IPv4 or IPv6 address. | ||
The `geoip` module provides a simple way to determine the geographical location of an IPv4 or IPv6 address. | ||
This includes details such as longitude, latitude, country, city, and continent. | ||
|
||
## Features | ||
|
||
## Usage | ||
|
||
To get the location of the system calling this function, use exported method `Fetch` from the package `geoip` | ||
- **Failover Mechanism:** The module attempts to fetch location data from multiple services to ensure high availability. If one URL fails, it logs the error and retries with the next URL. | ||
- **Structured Location Data:** Returns structured data in a `Location` struct for easy integration. | ||
|
||
1. use `geoip.Fetch()`: | ||
```go | ||
type Location struct { | ||
Longitude float64 `json:"longitude"` | ||
Latitude float64 `json:"latitude"` | ||
Continent string `json:"continent"` | ||
Country string `json:"country_name"` | ||
CountryCode string `json:"country_code"` | ||
City string `json:"city_name"` | ||
} | ||
``` | ||
|
||
This method uses 3 paths of geoip, It starts with first path of `geoipURLs` if any error was produced it continues and tries out the next path, REturnes the default unknown location and the error in case it couldn't receive correct response from all paths. | ||
|
||
## Tests | ||
## Usage | ||
|
||
`geoip_test.go` tests the driver function `getLocation` which is called by the exported function `Fetch` | ||
It mainly tests and validates: | ||
1. Correct response. | ||
2. Wrong response code. | ||
3. Wrong response body. | ||
The module provides a single exported function: `Fetch`. | ||
|
||
#### Remark : Tests are computed on all 3 paths of `geoipURLs` to ensure correctness. | ||
The `Fetch` function retrieves the geographical location of the system calling the function. |