// AddRoutes adds routes to a router instance. If there are middlewares defined // for a route, a new negroni app is created and wrapped as a http.Handler func AddRoutes(routes []Route, router *mux.Router) { var ( handler http.Handler n *negroni.Negroni ) for _, route := range routes { // Add any specified middlewares if len(route.Middlewares) > 0 { n = negroni.New() for _, middleware := range route.Middlewares { n.Use(middleware) } // Wrap the handler in the negroni app with middlewares n.Use(negroni.Wrap(route.HandlerFunc)) handler = n } else { handler = route.HandlerFunc } router.Methods(route.Method). Path(route.Pattern). Name(route.Name). Handler(handler) } }
func BonitosrvQuery(n *negroni.Negroni, method string, url string, data io.Reader) *httptest.ResponseRecorder { request, _ := http.NewRequest(method, url, data) response := httptest.NewRecorder() n.ServeHTTP(response, request) return response }
// Configure creates a default newrelic client and adds middleware and such func Configure(n *negroni.Negroni) error { cfg, err := config.LoadEnv() if err != nil { return err } ctl := control.NewAgentController(cfg) n.Use(NewRelicMiddleware(ctl, cfg)) return nil }
// Register wires up all middleware for the web app func Register(n *negroni.Negroni) { n.Use(negroni.NewRecovery()) n.Use(negroni.NewLogger()) }
// Inject adds x-request-id and x-forwarded-for support to an existing negroni instance. func Inject(n *negroni.Negroni) { n.Use(negroni.HandlerFunc(xff.XFF)) n.Use(xrequestid.New(26)) }