Ejemplo n.º 1
0
func createTestRouter(apiPath string) *routes.Router {
	ds, err := datastore.Open("sqlite3", "file:test.db?cache=shared&mode=memory")
	if err != nil {
		panic(err)
	}

	migrationsPath := config.GetString(keys.DatabaseMigrationsPath)
	if migrationsPath == "" {
		panic("Migrations path has not been defined.")
	}

	errs, ok := ds.UpSync(migrationsPath)
	if !ok {
		errMsg := ""
		for _, err := range errs {
			errMsg = errMsg + err.Error()
		}

		panic(errMsg)
	}

	dao := users.NewDao(ds)

	err = dao.Insert(testUser)
	if err != nil {
		panic(err)
	}

	return NewRouter(apiPath, dao)
}
Ejemplo n.º 2
0
func NewServer(db *datastore.DB) *Server {
	userDao := users.NewDao(db)
	wizardDao := wizards.NewDao(db)

	router := mux.NewRouter()

	// Add API endpoints
	apiRouter := api.NewRouter(apiPath, userDao)
	router.PathPrefix(apiPath).Handler(apiRouter)

	// Add view endpoints
	viewsRouter := views.NewRouter(viewsPath, userDao, wizardDao)
	router.PathPrefix(viewsPath).Handler(viewsRouter)

	return &Server{Router: router}
}