// ExpireOldVehicles deletes all vehicles older than a day
func expireOldVehicles(expDate time.Time) {
	db, err := storage.CreateConnection()
	if err != nil {
		log.Println(err)
	}
	defer db.Close()
	storage.RemoveVehiclesOlderThan(db, expDate)
}
Beispiel #2
0
func fetchTransit(lines []string) error {
	vehicles, err := muni.GetMultiVehicleData(lines)
	if err != nil {
		return err
	}
	db, err := storage.CreateConnection()
	if err != nil {
		log.Println(db)
		return err
	}
	defer db.Close()
	for _, v := range vehicles {
		storage.InsertVehicle(db, v)
	}
	return nil
}
Beispiel #3
0
// AllVehicles returns all of the vehicles in the system
func AllVehicles(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	db, err := storage.CreateConnection()
	if err != nil {
		log.Println("Error connecting to DB in AllVehicles")
		return
	}
	defer db.Close()
	vd, err := storage.GetVehiclesAfterTime(db, time.Now().Add(time.Minute*-4))
	compacted := utils.CompactVehicles(vd)
	out, err := json.Marshal(compacted)
	if err != nil {
		log.Println(err)
	}
	fmt.Fprint(w, string(out))
}