A Golang-based location based redirection service that redirects incoming requests to backend servers based on the client's location (URL mapping rules). The proxy server supports location-based server selection for global scalability.
In cloud-deployed systems, scalability is crucial to handle on-demand requests efficiently. This location based redirection service allows redirection of incoming requests to backend servers based on customizable URL mapping rules. Each incoming URL can be redirected to different backend servers avoiding reliance on a single server.
- URL Mapping: Customize URL mapping rules to redirect incoming requests to specific backend servers.
- Location-Based Server Selection: Redirects requests based on the client's location, ensuring optimal performance for global users.
- Error Handling: Handles cases where no mapping is found and returns a "Not Found" response (404).
- Configurable: Easily modify the mapping rules through the JSON configuration file.
- Testing: Includes comprehensive unit tests to ensure the correctness of the redirection process.
- Clone the repository to your local machine:
git clone https://github.com/garghub/location_based_redirection_golang.git
- Change into the project directory:
cd location_based_redirection_golang
- Install the necessary dependencies:
go mod download
- Customize the IP address location mapping rules in the
mapping_rules.json
file. Add the path, locations, and their corresponding backend URLs. For example, a client is connecting via an IP address that, as per IP-API, is in Australia, then a new location with "Australia" and an appropriate redirecting URL can be added. Here is an example of the existing mapping:
{
"rules": [
{
"path": "/search",
"locations": {
"United States": "https://duckduckgo.com/?q=news",
"Luxembourg": "https://www.bing.com/search?q=news",
"Default": "https://www.google.com/search?q=news"
}
}
]
}
- Run the proxy server:
go run main.go
- The proxy server will run on port 8080.
The configuration file mapping_rules.json
is used to set up the URL mapping rules for the proxy server. Customize the file with the desired URL paths and their corresponding backend URLs. You can add more rules to support additional paths.
To run the unit tests, execute the following command:
go test
- Location identification based on IP address
- URL redirection to Bing for clients in Luxembourg
- URL redirection to Duckduckgo for clients in US
- URL redirection to Google for clients in any location other than US and Luxembourg
- Page Not Found (404) is shown in case of an incorrect URL
This project is being maintained and improved. I intend to follow best practices in development and welcome feedback.
This project is licensed under the MIT License.