jonmorehouse / gatekeeper

a pluggable http routing runtime
12 stars 1 forks source link

go-plugin + static routes plugin #3

Closed jonmorehouse closed 8 years ago

jonmorehouse commented 8 years ago

So the next step after we've implemented some basic networking over in #2 is to set up some basic scaffolding for fetching the correct route information for a request.

Thinking through this now, it seems like we should "upstream" plugins which for now is just a plugin returning static urls. It seems to me like the gatekeepers primary process should maintain a local cache of the upstreams it knows about, whilst exposing a method for individual plugins to call into and update.

As a first pass, it can be single-direction communication and each request to the proxy can call into the upstreams plugin (no caching yet).

Off the top of my head, each upstream should have the following parameters;

As a first pass, I think we can make the following assumption:

If hostnames is passed in, any request with a Host header linked to the upstream will NOT strip the prefix. eg:

curl -H 'Host: my-upstream' gatekeeper/foo/bar => foo_upstream/foo/bar

If a request just comes into the gatekeeper api with just a prefix, then we can assume that the prefix should be stripped before proxying on to the upstream.

curl gatekeeper/my-upstream/foo/bar => foo_upstream/bar
jonmorehouse commented 8 years ago

Just thinking through some directory structure here:

tree .
.
├── bins
│   ├── gatekeeper
│   ├── plugin-consul-upstreams
│   └── plugin-static-upstreams
├── gatekeeper
│   └── lib.go
├── main.go
└── plugins
    ├── plugin-consul-upstreams
    └── plugin-static-upstreams

Here's how I think this project should come out structured...

Notably, different "builtin" plugins are contained in the plugins directory. gatekeeper will be a module which is shared by the top level main package and modules within the plugins directory. In order to build any particular package, we'll simply need to add the gatekeeper module to our GOPATH in a deterministic manner.

jonmorehouse commented 8 years ago

So coming up with a parent-child plugin relationship ended up being tricky; here's some example code showing how this could all come out...

https://gist.github.com/jonmorehouse/75e02047ec5ac47a8109ba0ba13eea80

jonmorehouse commented 8 years ago

Closed by #7