//Use register middleware
481034
func (r *Router) Use(middlewares ...HandlerFunc) {
	for _, handler := range middlewares {
		r.handlers = append(r.handlers, handler)
	}
}
986465
func (app *App) Use(handle Middleware) *App {
	app.mds = append(app.mds, handle)
	return app
}
933134
func (r *Route) Middleware(m Middleware) *Route {
	r.middleware = append(r.middleware, &middlewareForVerb{
		mid:  m,
		verb: flagAny,
	})
	return r
}
956046
func (p *Mux) RegisterMethodNotAllowed(middleware ...Middleware) {

	p.handleMethodNotAllowed = true

	h := methodNotAllowedHandler

	for i := len(middleware) - 1; i >= 0; i-- {
		h = middleware[i](h)
	}

	p.http405 = h
}
313784
func Register(app *gramework.App, serviceName ...string) error {
	var m Middleware
	name := os.Args[0]
	if len(serviceName) > 0 {
		name = serviceName[0]
	}

	hostname, err := os.Hostname()
	if err != nil {
		return err
	}

	m.httpReqCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gramework_http_requests_total",
			Help: "Total count of HTTP requests processed, partitioned by code, method, path and type (HTTP/HTTPS)",
			ConstLabels: prometheus.Labels{
				"service": name,
				"node":    hostname,
			},
		},
		[]string{"code", "method", "path", "type"},
	)
	if err = prometheus.Register(m.httpReqCounter); err != nil {
		return err
	}

	m.reqDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "gramework_http_requests_duration_seconds",
			Help: "Request processing duration, partitioned by code, method, path and type (HTTP/HTTPS)",
			ConstLabels: prometheus.Labels{
				"service": name,
				"node":    hostname,
			},
		},
		[]string{"code", "method", "path", "type"},
	)

	if err = prometheus.Register(m.reqDuration); err != nil {
		return err
	}

	app.GET(string(metricsPath), gramework.NewGrameHandler(promhttp.Handler()))

	if err = app.UsePre(m.startReq); err != nil {
		return err
	}

	return app.UseAfterRequest(m.endReq)
}
114945
func (m *Manager) Middleware() func(http.Handler) http.Handler {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			rm := &scopedManager{
				Manager:        m,
				ResponseWriter: w,
				r:              r,
				storage:        make(map[string]*Session),
			}

			ctx := context.WithValue(r.Context(), scopedManagerKey{}, rm)
			h.ServeHTTP(rm, r.WithContext(ctx))

			rm.MustSaveAll()
		})
	}
}
1362874
func (r *Router) Use(mc MiddlewareChain) {
	r.middleware = r.middleware.ExtendFrom(mc)
}
1168726
func Middleware(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	var authToken string = strings.Replace(r.Header.Get("Authorization"), "Bearer ", "", 1)
	claims, err := getClaims(authToken)
	if err == nil || failRequest == false {
		if err == nil {
			context.Set(r, context_key, claims)
		}
		next(rw, r)
	} else {
		rw.WriteHeader(401)
	}
}
1019008
func (p *Prometheus) Use(e *gin.Engine) {
	e.Use(p.HandlerFunc())
	p.SetMetricsPath(e)
}
619511
func (d *Dispatcher) Register(rs []transport.Procedure) {
	procedures := make([]transport.Procedure, 0, len(rs))

	for _, r := range rs {
		switch r.HandlerSpec.Type() {
		case transport.Unary:
			h := middleware.ApplyUnaryInbound(r.HandlerSpec.Unary(),
				d.inboundMiddleware.Unary)
			r.HandlerSpec = transport.NewUnaryHandlerSpec(h)
		case transport.Oneway:
			h := middleware.ApplyOnewayInbound(r.HandlerSpec.Oneway(),
				d.inboundMiddleware.Oneway)
			r.HandlerSpec = transport.NewOnewayHandlerSpec(h)
		case transport.Streaming:
			h := middleware.ApplyStreamInbound(r.HandlerSpec.Stream(),
				d.inboundMiddleware.Stream)
			r.HandlerSpec = transport.NewStreamHandlerSpec(h)
		default:
			panic(fmt.Sprintf("unknown handler type %q for service %q, procedure %q",
				r.HandlerSpec.Type(), r.Service, r.Name))
		}

		procedures = append(procedures, r)
		d.log.Info("Registration succeeded.", zap.Object("registeredProcedure", r))
	}

	d.table.Register(procedures)
}
543920
func Setup(app *gramework.App) {
	err := app.UseAfterRequest(serveXHost)
	if err != nil {
		app.Logger.WithError(err).WithField("package", "mw/xhostname").Error("could not register middleware")
	}
}
52771
func (g *Group) Use(middleware ...MiddlewareFunc) {
	g.middleware = append(g.middleware, middleware...)
	if len(g.middleware) == 0 {
		return
	}
	// Allow all requests to reach the group as they might get dropped if router
	// doesn't find a match, making none of the group middleware process.
	g.Any("", NotFoundHandler)
	g.Any("/*", NotFoundHandler)
}
36354
func Use(handler http.Handler, middleware ...func(http.Handler) http.Handler) http.Handler {
	for _, m := range middleware {
		handler = m(handler)
	}
	return handler
}
80038
func (s *Server) Middleware(ware Middleware) {
	s.wares = append(s.wares, ware)
}
25598
func (r *Router) UseFunc(middlewareFuncs ...MiddlewareFunc) {
	for _, fn := range middlewareFuncs {
		r.Use(MiddlewareFunc(fn))
	}
}
633646
func Middleware(config Config) func(http.Handler) http.Handler {
	return New(config).Middleware()
}
859002
func (s *Layer) Use(plugin plugin.Plugin) Middleware {
	s.mtx.Lock()
	s.stack = append(s.stack, plugin)
	s.mtx.Unlock()
	return s
}