Пример #1
0
//GetRouter contructs the router hierarchy and registers all handlers and middleware
func GetRouter(sc *siteservice.Service, is *identityservice.Service, oauthsc *oauthservice.Service) http.Handler {
	r := mux.NewRouter().StrictSlash(true)

	sc.AddRoutes(r)
	sc.InitModels()

	apiRouter := r.PathPrefix("/api").Subrouter()
	is.AddRoutes(apiRouter)
	oauthsc.AddRoutes(r)

	// Add middlewares
	router := NewRouter(r)

	dbmw := db.DBMiddleware()
	recovery := handlers.RecoveryHandler()

	router.Use(recovery, LoggingMiddleware, dbmw, sc.SetWebUserMiddleWare)

	return router.Handler()
}
Пример #2
0
//GetRouter contructs the router hierarchy and registers all handlers and middleware
func GetRouter() http.Handler {
	r := mux.NewRouter().StrictSlash(true)

	siteservice := siteservice.NewService()
	siteservice.AddRoutes(r)

	apiRouter := r.PathPrefix("/api").Subrouter()
	identityservice.NewService().AddRoutes(apiRouter)

	oauthservice.NewService(siteservice).AddRoutes(r)

	// Add middlewares
	router := NewRouter(r)

	dbmw := db.DBMiddleware()
	recovery := handlers.RecoveryHandler()

	router.Use(recovery, LoggingMiddleware, dbmw)

	return router.Handler()
}