Skip to content

Commit

Permalink
update geoip docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Dec 4, 2024
1 parent 48be192 commit 19e5376
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions pkg/geoip/README.md
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.

0 comments on commit 19e5376

Please sign in to comment.