Exemple #1
0
func getAtomFeed(res http.ResponseWriter, req *http.Request) {
	feed := atom.Feed{
		Title:   "",
		Updated: atom.Time(time.Now()),
	}
	limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
	if err != nil {
		limit = 100
	}
	alerts, err := qcap.GetAlerts(limit)
	if err != nil {
		log.Panic("Error retrieving alerts:", err)
	}
	for _, a := range alerts {
		t := atom.Time(a.Id.Time())
		id := a.Id.Hex()
		e := atom.Entry{
			Title:     fmt.Sprint("Alert ", id),
			ID:        id,
			Published: t,
			Updated:   t,
			Link: []atom.Link{
				atom.Link{Rel: "self", Href: qcapBaseUrl + xmlEndpoint + "/alerts/" + id},
			},
		}
		feed.Entry = append(feed.Entry, &e)
	}
	r.XML(res, http.StatusOK, feed)
}
Exemple #2
0
func alertsGetJson(res http.ResponseWriter, req *http.Request) {
	limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
	if err != nil {
		limit = 100
	}
	alerts, err := qcap.GetAlerts(limit)
	if err != nil {
		log.Fatal(err)
	}
	r.JSON(res, http.StatusOK, alerts)
}