Beispiel #1
0
func main() {
	startUp()
	setCron()

	m := martini.Classic()
	m.Use(martini.Static("public"))
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", "xx")
	})

	m.Get("/recent",
		func(r render.Render) {
			r.JSON(200, entries)
		})

	m.Get("/recent/:laterThan",
		func(params martini.Params, r render.Render) {
			laterThan, err := strconv.Atoi(params["laterThan"])
			if err != nil {
				r.JSON(404, nil)
			}
			dayBefore, _ := util.GetDayBefore(laterThan)
			entries := mongo.GetDaysEntries(dayBefore, 5, 20)
			r.JSON(200, entries)
		})

	m.Get("/orgs",
		func(params martini.Params, r render.Render) {
			r.JSON(200, orgs)
		})

	m.Run()
}
Beispiel #2
0
func GetDaysEntries(from int, days int, threshold int) []model.DayEntries {
	entries := []model.DayEntries{}
	for i := 0; i < days; i++ {
		dayEntries := GetDayEntries(from)
		if len(dayEntries.Entries) > 0 {
			entries = append(entries, dayEntries)
			if util.CountDayEntries(entries) > threshold {
				break
			}
		}
		from, _ = util.GetDayBefore(from)
	}
	return entries
}