Beispiel #1
0
//The app engine will run its own main function and imports this code as a package
//So no main needs to be defined
//All routes go in to init
func init() {

	recentChangedQns = []string{}

	// Initialising stackongo session
	backend.NewSession()

	// goroutine to collect the questions from SO and add them to the database
	go func(db *sql.DB) {
		// Iterate over ([SPECIFIED DURATION])
		for _ = range time.NewTicker(timeout).C {
			toDate := time.Now()
			fromDate := toDate.Add(-1 * timeout)
			// Collect new questions from SO
			log.Println("Getting new questions")
			questions, err := backend.GetNewQns(fromDate, toDate)
			if err != nil {
				log.Printf("Error getting new questions: %v", err.Error())
				continue
			}

			log.Println("Adding questions to db")
			// Add new questions to database
			if err = backend.AddQuestions(db, questions); err != nil {
				log.Printf("Error updating database: %v", err.Error())
				continue
			}
		}
	}(db)

	log.Println("Initial cache download")
	initCacheDownload()

	// // goroutine to update local cache if there has been any change to database
	// count := 1
	// go func(count int) {
	// 	for {
	// 		if checkDBUpdateTime("questions", mostRecentUpdate) {
	// 			log.Printf("Refreshing cache %v", count)
	// 			refreshLocalCache()
	// 			count++
	// 		}
	// 	}
	// }(count)

	http.HandleFunc("/login", authHandler)
	http.HandleFunc("/", handler)
	http.HandleFunc("/tag", handler)
	http.HandleFunc("/user", handler)
	http.HandleFunc("/viewTags", handler)
	http.HandleFunc("/viewUsers", handler)
	http.HandleFunc("/userPage", handler)
	http.HandleFunc("/dbUpdated", updateHandler)
	http.HandleFunc("/search", handler)
}
Beispiel #2
0
//The app engine will run its own main function and imports this code as a package
//So no main needs to be defined
//All routes go in to init
func init() {
	recentChangedQns = []string{}
	lastPull = time.Now().Add(-1 * time.Hour * 24 * 7).Unix()

	// Initialising stackongo session
	backend.NewSession()

	// Handlers for pages
	http.HandleFunc("/login", authHandler)
	http.HandleFunc("/", handler)
	http.HandleFunc("/tag", handler)
	http.HandleFunc("/user", handler)
	http.HandleFunc("/viewTags", handler)
	http.HandleFunc("/viewUsers", handler)
	http.HandleFunc("/dbUpdated", updateHandler)
	http.HandleFunc("/search", handler)
	http.HandleFunc("/addQuestion", handler)
	http.HandleFunc("/pullNewQn", handler)
}