Compitable with context.Context middlewares #40

Open
opened 2017-05-07 03:12:06 +00:00 by lunny · 0 comments
Owner

Author: @lunny

Action is an interface in a middleware and context.Context is also an interface. There are some similar features 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.

Author: @lunny Action is an interface in a middleware and `context.Context` is also an interface. There are some similar features 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. ```Go func (ctx *tango.Ctx) { if sess, ok := ctx.Action().(Sessioner); ok { // do something } } ``` ```Go 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`.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lunny/tango#40
No description provided.