Пример #1
0
// FindRegion retrieves the stations for the specified region
func FindRegion(region string, limit int) ([]Station, error) {
	log.Printf("FindRegion : Started : region[%s]\n", region)

	var buoyStations []Station
	if err := mongodb.Execute("buoy_stations",
		func(collection *mgo.Collection) error {
			queryMap := bson.M{"region": region}

			log.Printf("FindRegion : MGO : db.buoy_stations.find(%s).limit(%d)\n", mongodb.Log(queryMap), limit)
			return collection.Find(queryMap).Limit(limit).All(&buoyStations)
		}); err != nil {
		if err != mgo.ErrNotFound {
			log.Println("FindRegion :", err)
			return nil, err
		}
	}

	log.Println("FindRegion : Completed")
	return buoyStations, nil
}
Пример #2
0
// FindStation retrieves the specified station
func FindStation(stationID string) (*Station, error) {
	log.Printf("FindStation : Started : stationID[%s]\n", stationID)

	var buoyStation *Station
	if err := mongodb.Execute("buoy_stations",
		func(collection *mgo.Collection) error {
			queryMap := bson.M{"station_id": stationID}

			log.Printf("FindStation : MGO : db.buoy_stations.find(%s).limit(1)\n", mongodb.Log(queryMap))
			return collection.Find(queryMap).One(&buoyStation)
		}); err != nil {
		if err != mgo.ErrNotFound {
			log.Println("FindStation :", err)
			return nil, err
		}
	}

	log.Println("FindStation : Completed")
	return buoyStation, nil
}