예제 #1
0
func runServer(cnf *config.Config, db *gorm.DB) {
	// Initialise the health service
	healthService := health.NewService(db)

	// Initialise the oauth service
	oauthService := oauth.NewService(cnf, db)

	// Initialise the web service
	webService := web.NewService(cnf, oauthService)

	// Start a classic negroni app
	app := negroni.Classic()

	// Create a router instance
	router := mux.NewRouter()

	// Add routes for the health service (healthcheck endpoint)
	health.RegisterRoutes(router, healthService)

	// Add routes for the oauth service (REST tokens endpoint)
	oauth.RegisterRoutes(router, oauthService)

	// Add routes for the web package (register, login authorize web pages)
	web.RegisterRoutes(router, webService)

	// Set the router
	app.UseHandler(router)

	// Run the server on port 8080
	app.Run(":8080")
}
예제 #2
0
func runServer(cnf *config.Config, db *gorm.DB) {
	// Initialise the oauth service
	oauthService := oauth.NewService(cnf, db)

	// Initialise the accounts service
	_ = accounts.NewService(cnf, db, oauthService)

	// Initialise the web service
	_ = web.NewService(cnf, oauthService)

	// Start a classic negroni app
	webApp := negroni.Classic()

	// Create a router instance
	router := mux.NewRouter().StrictSlash(true)

	// Add routes for the oauth package (REST tokens endpoint)
	routes.AddRoutes(oauth.Routes, router.PathPrefix("/api/v1/oauth").Subrouter())

	// Add routes for the web package (register, login authorize web pages)
	routes.AddRoutes(web.Routes, router.PathPrefix("/web").Subrouter())

	// Set the router
	webApp.UseHandler(router)

	// Run the server on port 8080
	webApp.Run(":8080")
}
예제 #3
0
// The SetupSuite method will be run by testify once, at the very
// start of the testing suite, before any tests are run.
func (suite *OauthTestSuite) SetupSuite() {
	// Initialise the config
	suite.cnf = config.NewConfig(false, false)

	// Create the test database
	db, err := testutil.CreateTestDatabasePostgres(
		testDbUser,
		testDbName,
		testMigrations,
		testFixtures,
	)
	if err != nil {
		log.Fatal(err)
	}
	suite.db = db

	// Fetch test client
	suite.clients = make([]*models.OauthClient, 0)
	if err := suite.db.Order("id").Find(&suite.clients).Error; err != nil {
		log.Fatal(err)
	}

	// Fetch test users
	suite.users = make([]*models.OauthUser, 0)
	if err := suite.db.Order("id").Find(&suite.users).Error; err != nil {
		log.Fatal(err)
	}

	// Initialise the service
	suite.service = oauth.NewService(suite.cnf, suite.db)

	// Register routes
	suite.router = mux.NewRouter()
	suite.service.RegisterRoutes(suite.router, "/v1/oauth")
}
예제 #4
0
// initServices starts up all services and sets above defined variables
func initServices(cnf *config.Config, db *gorm.DB) error {
	healthService = health.NewService(db)

	oauthService = oauth.NewService(cnf, db)

	webService = web.NewService(cnf, oauthService)

	return nil
}
예제 #5
0
// RunServer runs the app
func RunServer() error {
	cnf, db, err := initConfigDB(true, true)
	defer db.Close()
	if err != nil {
		return err
	}

	// Initialise the health service
	healthService := health.NewService(db)

	// Initialise the oauth service
	oauthService := oauth.NewService(cnf, db)

	// Initialise the web service
	webService := web.NewService(cnf, oauthService)

	// Start a classic negroni app
	app := negroni.New()
	app.Use(negroni.NewRecovery())
	app.Use(negroni.NewLogger())
	app.Use(gzip.Gzip(gzip.DefaultCompression))
	app.Use(negroni.NewStatic(http.Dir("public")))

	// Create a router instance
	router := mux.NewRouter()

	// Add routes for the health service (healthcheck endpoint)
	health.RegisterRoutes(router, healthService)

	// Add routes for the oauth service (REST tokens endpoint)
	oauth.RegisterRoutes(router, oauthService)

	// Add routes for the web package (register, login authorize web pages)
	web.RegisterRoutes(router, webService)

	// Set the router
	app.UseHandler(router)

	// Run the server on port 8080
	app.Run(":8080")

	return nil
}
예제 #6
0
func runServer(cnf *config.Config, db *gorm.DB) {
	// Initialise the oauth service
	oauthService := oauth.NewService(cnf, db)

	// Initialise the accounts service
	_ = accounts.NewService(cnf, db, oauthService)

	// Initialise the web service
	_ = web.NewService(cnf, oauthService)

	// Start a classic negroni app
	webApp := negroni.Classic()

	// Create a router instance
	router := mux.NewRouter().StrictSlash(true)

	var subRouter *mux.Router

	// Add routes for the oauth service
	subRouter = router.PathPrefix("/oauth/api/v1").Subrouter()
	for _, route := range oauth.Routes {
		var handler http.Handler
		if len(route.Middlewares) > 0 {
			n := negroni.New()
			for _, middleware := range route.Middlewares {
				n.Use(middleware)
			}
			n.Use(negroni.Wrap(route.HandlerFunc))
			handler = n
		} else {
			handler = route.HandlerFunc
		}

		subRouter.Methods(route.Methods...).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}

	// Add routes for web pages
	subRouter = router.PathPrefix("/web").Subrouter()
	for _, route := range web.Routes {
		var handler http.Handler
		if len(route.Middlewares) > 0 {
			n := negroni.New()
			for _, middleware := range route.Middlewares {
				n.Use(middleware)
			}
			n.Use(negroni.Wrap(route.HandlerFunc))
			handler = n
		} else {
			handler = route.HandlerFunc
		}

		subRouter.Methods(route.Methods...).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}

	// Set the router
	webApp.UseHandler(router)

	// Run the server on port 8080
	webApp.Run(":8080")
}