Build your API Gateway
Because of the plugins (middleware) is not possible to have a generic binary, therefore after creating the configuration file and based on the plugins defined the gateway needs to be build.
Setup go environment https://golang.org/doc/install
go >= 1.7 is required
For example using $HOME/go for your workspace
Create the directory:
mkdir -p $HOME/go/src/github.com/slashquery
Clone project into that directory:
git clone [email protected]:slashquery/slashquery.git $HOME/go/src/github.com/slashquery/slashquery
Create your configuration file and type
cd $HOME/go/src/github.com/slashquery/slashquery make CONFIG=/path/to/slashquery.yml
How it works
The routes section in the configuration file is
used to create the router
routes.go file is generated by running within the slashquery source
go run genroutes.go -f /path/to/slashquery.yml
Read more about go generate
genroutes.go parses the configuration file and creates the
based on defined plugins.
For example, for all the requests to path
/foo, if this plugins are defined:
See more about the plugins here.
The request flow would be something like this:
api.example.com/foo LoadBalancer --< upstream | (plugins/middleware) | | | `--> RequestID --> WAF --> CORS --> Promethehs´
The configuration file would be:
routes: foo: url: http://foo.example.com plugins: # the order of the plugins meters - requestid - waf - cors - prometheus plugins: cors: ["github.com/slashquery-plugins/cors", "cors.CORS"] csrf: ["github.com/slashquery-plugins/csrf", "csrf.CSRF"] prometheus: ["github.com/slashquery-plugins/prometheus", "prometheus.Prometheus"] requestid: ["github.com/slashquery-plugins/requestid", "requestid.RequestID"] waf: ["github.com/slashquery-plugins/waf", "waf.WAF"]
When adding plugins to a route, the order meters, this means that plugins are
called in the order that they are entered, in the previous example, the first
plugin to be called is
RequestID and the latest one
plugins section contains all the plugins available.