fastgate

command module
v0.0.0-...-17f4e14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2019 License: MIT Imports: 16 Imported by: 0

README

FastGateLogo

GoDoc Release License Go Report Card CircleCI

A Fast, light and Low Overhead API Gateway written in GO.

Fast, light and Low Overhead API Gateway written in GO FastGate works by either proxying or redirecting traffic to the correct IP.

Proxy VS Redirect

This Gateway was designed to work in two different modes. Here are a few differences, and how to chose them:

Proxy ( Enabled by Default) :

  • Can reach every network acessible by the Gateway, independent on the Client and Service.
  • All the data will be flowing trough this Gateway

Redirect ( Set ProxyMode to false in the Configuration ):

  • The connection with the Gateway will close right after the redirection, so the load will be minimum.
  • This method works only if the Client and the Server could reach eachother in the first place.

Installation

To install fastgate, you can download the latest release binary from the Dowload page , or compile it from source with GO.

Install Golang

If you need to install GO, please refer to the golang.org Download Page, and follow instructions, or use a package manager (Most are very outdated).

For macOS users, I do recommend installing from homebrew. The mantainers are doing a amazing job keeping up with updates. Note that you still need to configure home path, but brew itself will teach you on how to do it. Run : brew install go

Fastgate Source instalation

go get github.com/auyer/FastGate
cd $GOPATH/src/github.com/auyer/FastGate
go install

Deploy with Docker

By default, the Dockerfile picks the configuration file, TLS key and TLS cert from the same folder as the sourcecode.

  docker build -t fastgate .
  docker run -p YOUR_HTTP:8000 -p YOUR_HTTPS:8443 -d fastgate

Usage

  fastgate -config ./path_to_config_file

A sample to the configuration file can be found in config.model.json

To manually register (and test) FastGate, Send a POST request to yourip:yourport/fastgate/ with a JSON like follows:
{
  "address" : "https://yourEndpoint:8080"
  "resource"     : "resource-name"
}

Now send the desired request to fastgate-ip:fastgate-port/your_resource with the following header X-fastgate-resource : resource-name and it should be working !

Example curl commands:

Registering
  curl --request POST \
    --url http://localhost:8000/fastgate/ \
    --header 'content-type: application/json' \
    --data '{
      "address" : "http:/localhost:8080",
      "resource": "localapi"
      }
      '
Using route
  curl --request GET \
    --url http://localhost:8000/api/localresource/ \
    --header 'x-fastgate-resource: localapi'
Geting List of Registered routes
curl --request GET \
  --url http://localhost:8000/fastgate/ \
  --header 'content-type: application/json'

TODO

  • Write a To-Do list
  • Create List All Routes for debugging
  • Improve Testing on API routes
  • Create a Proxy Option for outside Networks
  • Benchmark comparing Redirect to Proxy
  • Define scope ( How simple shoud we keep it ?)

Documentation

Overview

Package main controls all features of the FastGate API Gateway.

To use this application, the user must send a POST request to /fastgate/ with the following body:

{
  "address" 	: "https://yourEndpoint:8080"
  "resource"	: "resource-name"
}

This will create an entry in the database with the resource-name as a Key, and the address as the value. To access the desired route afterwards, add the X-fastgate-resource header with resource-name as its value.

See this example below:

$ curl --request POST   --url http://localhost:8000/fastgate/   --header 'content-type: application/json'   --data '{
  "address" : "http://localhost:8080",
  "resource"     : "hello"
}'

> HTTP/1.1 201 Created

$ curl --request GET \
  --url http://localhost:8000/hello \
  --header 'x-fastgate-resource: hello'

> GET /hello HTTP/1.1 > Host: localhost:8000 > x-fastgate-resource: hello > < HTTP/1.1 307 Temporary Redirect < Location: http://localhost:8080/hello $ Hello !

To help with usage and debugging, there is a route for listing all registered routes. This list will be returned when requesting a GET on /fastgate/

See Example Below:

$ curl --request GET --url http://localhost:8000/fastgate/ --header 'content-type: application/json' -v > GET /fastgate/ HTTP/1.1 ... < HTTP/1.1 202 Accepted < Content-Type: application/json; charset=UTF-8 < Content-Length: 77 < [

{
  "address": "localapi",
  "resource": "http:/localhost:8080"
}

Package main controls all features of the FastGate API Gateway. FasGate API Gateway is an application that built with the Golang language

You can run FastGate with the following command: ```

fastgate -config ./path_to_config_file

```

 A sample to the configuration file can be found in config.model.json
To manually register (and test) FastGate, Send a POST request to `yourip:yourport/fastgate/` with a JSON like follows:

```

{
  "address" : "https://yourEndpoint:8080"
  "uri"     : "/api/your_resource"
}

``` ### Now send the desired request to `yourip:yourport/api/your_resource` and see it working !

Directories

Path Synopsis
Package config manages custom configuration for FastGate
Package config manages custom configuration for FastGate
Package db manages route storage for FastGate.
Package db manages route storage for FastGate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL