diff options
| author | Paul Mundt <paul.mundt@adaptant.io> | 2016-05-12 13:15:33 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2016-05-12 13:15:33 +0000 |
| commit | bb8476ffe78210d1a4c0b4bbee6da99da1bc15c5 (patch) | |
| tree | 5a70f855509889e02ea6df60d0b0fac208ee6f49 /src/dict2rest/main.go | |
| parent | a3a77dbd4ec45c17687d3e42dab551db59c93ca3 (diff) | |
| download | go-dict2rest-bb8476ffe78210d1a4c0b4bbee6da99da1bc15c5.tar.gz go-dict2rest-bb8476ffe78210d1a4c0b4bbee6da99da1bc15c5.tar.bz2 | |
Inhibit repeated handling of requests through context-aware middleware chains (#3)
* Squashed 'vendor/src/github.com/alexedwards/stack/' content from commit a4c0268
git-subtree-dir: vendor/src/github.com/alexedwards/stack
git-subtree-split: a4c0268505f12934376d6d8fdca232416861e271
* Use context-aware handler chains to limit repeated handling
Presently each middleware must advance through the handler chain to
reach the router endpoint. In the case of multiple compressors (gzip,
deflate) we need to be able to walk through the chain without additional
processing of already handled requests. This implements some simple
iteration logic based on request context that we pass down the chain.
Signed-off-by: Paul Mundt <paul.mundt@adaptant.io>
Diffstat (limited to 'src/dict2rest/main.go')
| -rw-r--r-- | src/dict2rest/main.go | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/dict2rest/main.go b/src/dict2rest/main.go index 391f97e..94e1ac2 100644 --- a/src/dict2rest/main.go +++ b/src/dict2rest/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "github.com/julienschmidt/httprouter" - "github.com/justinas/alice" + "github.com/alexedwards/stack" "github.com/rs/cors" "github.com/stretchr/graceful" "log" @@ -64,23 +64,18 @@ func main() { }, }) - stdChain := alice.New(cors.Handler, Logger) + stdChain := stack.New(stack.Adapt(cors.Handler), stack.Adapt(Logger)) if *gzip { stdChain = stdChain.Append(Gzip) log.Println("Adding support for Gzip compression") } if *deflate { - // Temporary limitation until the iteration logic is fixed up - if *gzip { - log.Println("Not enabling DEFLATE, presently only one compression method can be active at a time") - } else { - stdChain = stdChain.Append(Deflate) - log.Println("Adding support for DEFLATE compression") - } + stdChain = stdChain.Append(Deflate) + log.Println("Adding support for DEFLATE compression") } - chain := stdChain.Then(router) + chain := stdChain.ThenHandler(router) listen := ":" + *port |
