func (s *server) handleWithMiddleware( ctx types.Context, route types.Route) types.APIFunc { /*if route.GetMethod() == "HEAD" { return route.GetHandler() }*/ handler := route.GetHandler() middlewaresForRouteName, ok := s.routeHandlers[route.GetName()] if !ok { ctx.Warn("no middlewares for route") } else { for h := range reverse(middlewaresForRouteName) { handler = h.Handler(handler) ctx.WithField( "middleware", h.Name()).Debug("added route middleware") } } // add the global handlers for h := range reverse(s.globalHandlers) { handler = h.Handler(handler) ctx.WithField( "middleware", h.Name()).Debug("added global middleware") } return handler }
func (s *server) addRouterMiddleware( r types.Route, middlewares ...types.Middleware) { middlewaresForRouteName, ok := s.routeHandlers[r.GetName()] if !ok { middlewaresForRouteName = []types.Middleware{} } middlewaresForRouteName = append(middlewaresForRouteName, middlewares...) s.routeHandlers[r.GetName()] = middlewaresForRouteName }