Skip to content

Commit 19e5376

Browse files
committed
update geoip docs
1 parent 48be192 commit 19e5376

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

pkg/geoip/README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
# Geoip module
1+
# Geoip Module
22

3-
This module is used to get information about the geographical location of an IPv4 or IPv6 address.
3+
The `geoip` module provides a simple way to determine the geographical location of an IPv4 or IPv6 address.
4+
This includes details such as longitude, latitude, country, city, and continent.
45

6+
## Features
57

6-
## Usage
7-
8-
To get the location of the system calling this function, use exported method `Fetch` from the package `geoip`
8+
- **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.
9+
- **Structured Location Data:** Returns structured data in a `Location` struct for easy integration.
910

10-
1. use `geoip.Fetch()`:
11+
```go
12+
type Location struct {
13+
Longitude float64 `json:"longitude"`
14+
Latitude float64 `json:"latitude"`
15+
Continent string `json:"continent"`
16+
Country string `json:"country_name"`
17+
CountryCode string `json:"country_code"`
18+
City string `json:"city_name"`
19+
}
20+
```
1121

12-
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.
13-
14-
## Tests
22+
## Usage
1523

16-
`geoip_test.go` tests the driver function `getLocation` which is called by the exported function `Fetch`
17-
It mainly tests and validates:
18-
1. Correct response.
19-
2. Wrong response code.
20-
3. Wrong response body.
24+
The module provides a single exported function: `Fetch`.
2125

22-
#### Remark : Tests are computed on all 3 paths of `geoipURLs` to ensure correctness.
26+
The `Fetch` function retrieves the geographical location of the system calling the function.

0 commit comments

Comments
 (0)