Beispiel #1
0
func getFeed(w http.ResponseWriter, r *http.Request) {
	feedName := chi.URLParam(r, "feedName")

	feedSettings, err := config.LoadWidget(feedName)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	var items config.FeedItems

	feed, err := rss.Fetch(feedSettings.RssURL)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	for _, i := range feed.Items {
		items.ParseItem(i)
	}

	items, err = config.SaveFeed(feedName, items, feedSettings.Count)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"feed": items, "success": true})
}
Beispiel #2
0
func getWidgetByName(w http.ResponseWriter, r *http.Request) {
	widgetName := chi.URLParam(r, "widgetName")
	resp, err := config.LoadWidget(widgetName)

	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"widgetName": widgetName, "widget": resp, "success": true})
}