GithubHelp home page GithubHelp logo

garghub / location_based_redirection_golang Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 972 KB

Location guided load balancer | Redirection of URL based on IP location

License: MIT License

Go 100.00%
golang ipaddress-tracker load-balancer location-tracking

location_based_redirection_golang's Introduction

Location based redirection service in golang

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.

Table of Contents

Background

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.

Features

  • 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.

Installation

  1. Clone the repository to your local machine:
git clone https://github.com/garghub/location_based_redirection_golang.git
  1. Change into the project directory:
cd location_based_redirection_golang
  1. Install the necessary dependencies:
go mod download

Usage

  1. 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"
            }
        }
    ]
}
  1. Run the proxy server:
go run main.go
  1. The proxy server will run on port 8080.

Configuration

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.

Testing

To run the unit tests, execute the following command:

go test

Screenshots

  1. Location identification based on IP address

Screenshot 1

  1. URL redirection to Bing for clients in Luxembourg

Screenshot 2

  1. URL redirection to Duckduckgo for clients in US

Screenshot 3

  1. URL redirection to Google for clients in any location other than US and Luxembourg

Screenshot 4

  1. Page Not Found (404) is shown in case of an incorrect URL

Screenshot 5

Project Status

This project is being maintained and improved. I intend to follow best practices in development and welcome feedback.

License

This project is licensed under the MIT License.


location_based_redirection_golang's People

Contributors

garghub avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.