Questions tagged [go-alice]

When using several middlewares, with the standard Go network package, they are chained them like this:

Middleware1(Middleware2(Middleware3(App)))

Alice allows to chain them in a more convenient and readable way:

alice.New(Middleware1, Middleware2, Middleware3).Then(App)

More information is available on the project home page.

5 questions
12
votes
4 answers

How can I combine Go middleware pattern with error returning request handlers?

I am familiar with the Go middleware pattern like this: // Pattern for writing HTTP middleware. func middlewareHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Our…
Alex
  • 5,671
  • 9
  • 41
  • 81
3
votes
1 answer

HTTP Router and Middleware

I'm using Julien Schmidt's router for GoLang and trying to get it working with Alice to chain middleware. I'm getting this error: cannot use commonHandlers.ThenFunc(final) (type http.Handler) as type httprouter.Handle in argument to router.GET and…
tommyd456
  • 10,443
  • 26
  • 89
  • 163
3
votes
1 answer

Accessing Basic Auth credentials

I'm working on an API using GoLang. All calls to this API will contain a public_key (username) and some will also contain a private_key (password) in the Authorization header. I'm trying to figure out how to access the Auth header details so that I…
tommyd456
  • 10,443
  • 26
  • 89
  • 163
1
vote
1 answer

Build fails when passing custom middleware type to alice.New() function

This is about an error I am getting while I try to build my application. I use Gorilla mux as a router and Alice for chaining the middlewares. And I defined a custom type named 'Middleware' with the following signature; type Middleware…
0
votes
1 answer

Middleware using Alice and HttpRouter

I can't seem to work out how to use middleware and Http Router properly together. My code is: type appContext struct { db *mgo.Database } func main(){ c := appContext{session.DB("db-name")} commonHandlers := alice.New(context.ClearHandler,…
tommyd456
  • 10,443
  • 26
  • 89
  • 163