code: func NewMiddleware(m interface{}) (mw Middleware, err error) {
  	switch m := m.(type) {
  	case Middleware:
  		mw = m
  	case func(Handler) Handler:
  		mw = m
  	case Handler:
  		mw = handlerToMiddleware(m)
  	case func(context.Context, http.ResponseWriter, *http.Request) error:
  		mw = handlerToMiddleware(m)
  	case func(http.Handler) http.Handler:
  		mw = func(h Handler) Handler {
  			return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) {
  				m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  					err = h(ctx, w, r)
  				})).ServeHTTP(rw, req)
  				return
  			}
  		}
  	case http.Handler:
  		mw = httpHandlerToMiddleware(m.ServeHTTP)
  	case func(http.ResponseWriter, *http.Request):
  		mw = httpHandlerToMiddleware(m)
  	default:
  		err = fmt.Errorf("invalid middleware %#v", m)
  	}
  	return
  }
docs: // NewMiddleware creates a middleware from the given argument. The allowed types for the
  // argument are:
  //
  // - a goa middleware: goa.Middleware or func(goa.Handler) goa.Handler
  //
  // - a goa handler: goa.Handler or func(context.Context, http.ResponseWriter, *http.Request) error
  //
  // - an http middleware: func(http.Handler) http.Handler
  //
  // - or an http handler: http.Handler or func(http.ResponseWriter, *http.Request)
  //
  // An error is returned if the given argument is not one of the types above.