tango icon indicating copy to clipboard operation
tango copied to clipboard

Compitable with context.Context middlewares

Open lunny opened this issue 8 years ago • 0 comments

Action is an interface in an middleware and context.Context is also an interface. Their are some similar feature between Action and context.Context. In tango, we use assert to get the info from Action, in context.Context, it's also a regular usage get info via assert.

func (ctx *tango.Ctx) {
     if sess, ok := ctx.Action().(Sessioner); ok {
           // do something
    }
}
func (resp http.ResponseWriter, req *http.Request) {
    if sess, ok := req.Context().(Sessioner); ok {
          // do something 
   }
}

So that maybe all the tango's middlewares could be changed slightly to apply in http.Handler.

lunny avatar May 07 '17 03:05 lunny